value to serializa
(optional) serialization param
(optional) serialization target ID
UTF-8 YAML text
import mir.test: should; static struct S { string foo; uint bar; } S("str", 4).serializeYaml.should == `{foo: str, bar: 4} `;
Tags (annotations) support
import mir.test: should; import mir.algebraic: Variant; import mir.serde: serdeAlgebraicAnnotation; import mir.test: should; import mir.algebraic: Variant; import mir.serde: serdeAlgebraicAnnotation, serdeAnnotation, serdeOptional; @serdeAlgebraicAnnotation("!S") static struct S { string foo; uint bar; } @serdeAlgebraicAnnotation("rgb") static struct RGB { @serdeAnnotation @serdeOptional string name; ubyte r, g, b; } alias V = Variant!(S, RGB); S("str", 4).serializeYaml.should == "{foo: str, bar: 4}\n"; V("str", 4).serializeYaml.should == "!S {foo: str, bar: 4}\n"; // Multiple Ion annotations represented in a single tag using `::`. V(RGB("dark_blue", 23, 25, 55)).serializeYaml.should == `!<rgb::dark_blue> {r: 23, g: 25, b: 55} `;
YAML-specific serialization
import mir.algebraic_alias.yaml: YamlAlgebraic, YamlCollectionStyle; import mir.test: should; auto value = YamlAlgebraic(["foo".YamlAlgebraic, 123.9.YamlAlgebraic, "bar".YamlAlgebraic]); value.serializeYaml.should == "[foo, 123.9, bar]\n"; value.collectionStyle = YamlCollectionStyle.block; value.serializeYaml.should == "- foo\n- 123.9\n- bar\n";
User API for YAML-specific serialization
import mir.algebraic_alias.yaml: YamlAlgebraic; import mir.test: should; static struct MyYamlStruct { int b; // has to be scope const auto opCast(T : YamlAlgebraic)() scope const @safe pure { return b.YamlAlgebraic; } } MyYamlStruct(40).serializeYaml.should == "40\n";
Ion serialization function.