var.idup

var idup() const @safe

Create an immutable deep copy of this var.

This method is functionally equivalent to dup() since var itself is a mutable struct. The returned value is a regular var that can be assigned to an immutable(var) if needed.

Note

D's immutable applies to the variable binding, not the internal structure.

For true immutability of nested data, consider using immutable(var) at the declaration site after calling idup().

Returns

A new var that is a deep copy of this value.

Examples

var original = var([1, 2, 3]);
immutable(var) frozen = original.idup;