diff --git a/dyaml/constructor.d b/dyaml/constructor.d index 6ccc3d0..039c8d5 100644 --- a/dyaml/constructor.d +++ b/dyaml/constructor.d @@ -369,8 +369,8 @@ final class Constructor return (ref Node n) { - static if(Node.Value.allowed!T){return Node.Value(ctor(n));} - else {return Node.userValue(ctor(n));} + static if(Node.allowed!T){return Node.value(ctor(n));} + else {return Node.userValue(ctor(n));} }; } diff --git a/dyaml/node.d b/dyaml/node.d index 4e09031..de3ed71 100644 --- a/dyaml/node.d +++ b/dyaml/node.d @@ -1336,6 +1336,28 @@ struct Node return Value(cast(YAMLObject)new YAMLContainer!T(value)); } + //Construct Node.Value from a type it can store directly (after casting if needed) + static Value value(T)(T value) @trusted if(allowed!T) + { + static if(Value.allowed!T) + { + return Value(value); + } + else static if(isIntegral!T) + { + return Value(cast(long)(value)); + } + else static if(isFloatingPoint!T) + { + return Value(cast(real)(value)); + } + else static if(isSomeString!T) + { + return Value(to!string(value)); + } + else static assert(false, "Unknown value type. Is value() in sync with allowed()?"); + } + /* * Equality test with any value. *