diff --git a/dyaml/node.d b/dyaml/node.d index f66eef0..09778fd 100644 --- a/dyaml/node.d +++ b/dyaml/node.d @@ -158,6 +158,19 @@ struct Node return cmp!(Yes.useTag)(rhs) == 0; } + /// Assignment (shallow copy) by value. + void opAssign(Pair rhs) @safe + { + opAssign(rhs); + } + + /// Assignment (shallow copy) by reference. + void opAssign(ref Pair rhs) @safe + { + key = rhs.key; + value = rhs.value; + } + private: /* * Comparison with another Pair. @@ -875,6 +888,30 @@ struct Node assert(mapNan.containsKey(double.nan)); } + /// Assignment (shallow copy) by value. + void opAssign(Node rhs) @safe + { + opAssign(rhs); + } + + /// Assignment (shallow copy) by reference. + void opAssign(ref Node rhs) @safe + { + value_ = rhs.value_; + startMark_ = rhs.startMark_; + tag_ = rhs.tag_; + scalarStyle = rhs.scalarStyle; + collectionStyle = rhs.collectionStyle; + } + // Unittest for opAssign(). + unittest + { + auto seq = Node([1, 2, 3, 4, 5]); + auto assigned = seq; + assert(seq == assigned, + "Node.opAssign() doesn't produce an equivalent copy"); + } + /** * Set element at specified index in a collection. *