Representer.representScalar

Represent a _scalar with specified _tag.

This is used by representer functions that produce scalars.

class Representer
@trusted
representScalar

Parameters

scalar string

Scalar value.

style ScalarStyle

Style of the _scalar. If invalid, default _style will be used. If the node was loaded before, previous _style will always be used.

Return Value

Type: Node

The represented node.

Examples

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;
    }        
}

Node representMyStruct(ref Node node, Representer representer)
{ 
    auto value = node.as!MyStruct;
    auto scalar = format("%s:%s:%s", value.x, value.y, value.z);
    return representer.representScalar("!mystruct.tag", scalar);
}

Meta