Construct a Rebindable from a value.
Destroys the stored value. This is equivalent to a variable going out of scope.
Get a copy of a previously stored value.
Move-return the stored value by value. This is equivalent to get followed by destroy.
Replace a currently stored value with a new value. This is equivalent to destroy followed by set.
Set the Rebindable to a new value. Calling this function while an existing value is stored is undefined. The passed value is copied.
import rebindable.Rebindable : Rebindable; struct DataStructure(T) { private Rebindable!T store; this(T value) { this.store.set(value); } ~this() { this.store.destroy; } T get() { return this.store.get; } void set(T value) { this.store.replace(value); } } DataStructure!(const int) ds; ds.set(5); assert(ds.get == 5);
Rebindable!T is a container for T that permits managing T's lifetime explicitly.