var.opAssign

var opAssign(T)(T rhs) @safe

Assign from an arbitrary value rhs, setting the internal type and payload accordingly.

Shallow Copy Warning: When assigning from another var that contains an ARRAY or

OBJECT, this operation performs a shallow copy — the underlying container reference is aliased, not duplicated. This means:

var a = var([1, 2, 3]);
var b = a;          // b aliases a's array
b[0] = 99;          // modifies a[0] as well!
assert(a[0].as!int == 99);  // true — both see the change

To create an independent copy, use dup() or idup():

var a = var([1, 2, 3]);
var b = a.dup();    // b has its own copy
b[0] = 99;
assert(a[0].as!int == 1);   // a is unchanged

This shallow-copy behavior is intentional for performance (avoiding deep copies on every assignment), but users must be aware of the aliasing implications for container types.

Parameters

rhsThe value to assign.

Returns

A reference to this for chaining.