-
-
Save CyberShadow/dbc8232ab534a980871eab525ba9182e 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) | |
{ | |
Quality q; | |
switch(s){ | |
case "low": | |
q = Low(); break; | |
case "high": | |
q = High(); break; | |
case "medium": | |
q = Medium(); break; | |
case "original": | |
q = Original(); break; | |
default: | |
assert(false); | |
} | |
return q; | |
} | |
void main(){ | |
writeln("high".asQEnum); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment