Skip to content

Instantly share code, notes, and snippets.

@run-dlang
Created September 17, 2019 16:39
Show Gist options
  • Save run-dlang/3a7bc2d269921f68c8b708fb30085d56 to your computer and use it in GitHub Desktop.
Save run-dlang/3a7bc2d269921f68c8b708fb30085d56 to your computer and use it in GitHub Desktop.
Code shared from run.dlang.io.
/+dub.sdl:
dependency "sumtype" version="~>0.8.11"
+/
import std.stdio;
import sumtype;
struct High {}
struct Low{}
struct Medium{}
struct Original{}
struct None{};
alias Quality = SumType!(High, Medium, Low, Original);
@safe pure Quality asQEnum(string s)
{
switch(s){
case "low":
return Quality(Low());
case "high":
return Quality(High());
case "medium":
return Quality(Medium());
case "original":
return Quality(Original());
default:
assert(false);
}
}
void main(){
writeln("high".asQEnum);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment