var.as

T as(T)() const @safe

Convert the stored value to type T.

Conversion rules:

  • If the current type is Type.NULL, this returns T.init.
  • Scalars and strings convert via std.conv.to.
  • If the current type is Type.ARRAY and T is var[],

a copy of the underlying array is returned. If T is string, this returns the textual representation from toString().

  • If the current type is Type.OBJECT (map) and T is var[string],

a copy of the underlying map is returned. If T is string, this returns the textual representation from toString().

  • For other combinations, behavior is currently T.init.