Created
September 17, 2019 16:39
-
-
Save run-dlang/3a7bc2d269921f68c8b708fb30085d56 to your computer and use it in GitHub Desktop.
Code shared from run.dlang.io.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/+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