Node.this

Construct a Node from a value.

Any type except for Node can be stored in a Node, but default YAML types (integers, floats, strings, timestamps, etc.) will be stored more efficiently. To create a node representing a null value, construct it from YAMLNull.

If value is a node, its value will be copied directly. The tag and other information attached to the original node will be discarded.

If value is an array of nodes or pairs, it is stored directly. Otherwise, every value in the array is converted to a node, and those nodes are stored.

Note that to emit any non-default types you store in a node, you need a Representer to represent them in YAML - otherwise emitting will fail.

  1. this(T value, string tag)
    struct Node
    @safe
    this
    (
    T
    )
    (,
    const string tag = null
    )
    if (
    allowed!T ||
    isArray!T
    ||
    isAssociativeArray!T
    ||
    is(Unqual!T == Node)
    ||
    )
  2. this(K[] keys, V[] values, string tag)

Parameters

tag string

Overrides tag of the node when emitted, regardless of tag determined by Representer. Representer uses this to determine YAML data type when a D data type maps to multiple different YAML data types. Tag must be in full form, e.g. "tag:yaml.org,2002:int", not a shortcut, like "!!int".

Examples

Construct a scalar node

// Integer
{
    auto node = Node(5);
}
// String
{
    auto node = Node("Hello world!");
}
// Floating point
{
    auto node = Node(5.0f);
}
// Boolean
{
    auto node = Node(true);
}
// Time
{
    auto node = Node(SysTime(DateTime(2005, 6, 15, 20, 0, 0), UTC()));
}
// Integer, dumped as a string
{
    auto node = Node(5, "tag:yaml.org,2002:str");
}

Construct a sequence node

// Will be emitted as a sequence (default for arrays)
{
    auto seq = Node([1, 2, 3, 4, 5]);
}
// Will be emitted as a set (overridden tag)
{
    auto set = Node([1, 2, 3, 4, 5], "tag:yaml.org,2002:set");
}
// Can also store arrays of arrays
{
    auto node = Node([[1,2], [3,4]]);
}

Construct a mapping node

// Will be emitted as an unordered mapping (default for mappings)
auto map   = Node([1 : "a", 2 : "b"]);
// Will be emitted as an ordered map (overridden tag)
auto omap  = Node([1 : "a", 2 : "b"], "tag:yaml.org,2002:omap");
// Will be emitted as pairs (overridden tag)
auto pairs = Node([1 : "a", 2 : "b"], "tag:yaml.org,2002:pairs");

Meta