import std.string; import dyaml.all; struct MyStruct { int x, y, z; //Any D:YAML type must have a custom opCmp operator. //This is used for ordering in mappings. const int opCmp(ref const MyStruct s) { if(x != s.x){return x - s.x;} if(y != s.y){return y - s.y;} if(z != s.z){return z - s.z;} return 0; } } MyStruct constructMyStructSequence(ref Node node) { //node is guaranteed to be sequence. //!mystruct [x, y, z] return MyStruct(node[0].as!int, node[1].as!int, node[2].as!int); } void main() { auto loader = Loader("file.yaml"); auto constructor = new Constructor; constructor.addConstructorSequence("!mystruct", &constructMyStructSequence); loader.constructor = constructor; Node node = loader.load(); }
addConstructorScalar
Add a constructor function from sequence.