ddn.var — a compact, dynamic value type.
Error handling strategy:
- By default, wrong-type use of container APIs throws exceptions (e.g. indexing a non-object or using array APIs on non-arrays). This is enforced in both debug and
-release builds. - If compiled with
version(DDN_VAR_TYPE_COERCE), var becomes permissive: - Mutating/ref-returning array/object APIs will auto-coerce the value to the required container type (overwriting the previous value).
- Read-only accessors return neutral values on mismatch (no hidden mutation).
- In
debug builds, coercions emit warnings on stderr. - No I/O is performed inside this module except the documented debug-only coercion warnings on
stderr under version(DDN_VAR_TYPE_COERCE); formatting is provided by toString().
Thread-safety notes:
var itself does not perform any internal synchronization. Concurrent mutation of the same instance from multiple threads is a data race and is not supported.- Independent copies may be used in different threads; however, keep in mind that
string is immutable (safe to share) while arrays/maps inside var are reference-backed containers owned by each var instance. Note
copying/assignment of var values is shallow for Type.ARRAY and Type.OBJECT (it aliases the underlying containers). Use dup() / idup() when you need an independent deep copy.
- Recommended patterns: message passing of
var values; publishing immutable(var) snapshots; or guarding shared access with user-provided synchronization (e.g., a Mutex).
Nested Templates
TypeThe concrete type of a `var` value.
ElementTypeElement kind of a native-array value (`Type.NATIVE_ARRAY`).
NativeQualElement qualifier recorded at native-array construction. Controls whether a mutable view may be handed out; const views are always safe.
DecimalCapFixed-decimal capacity of a `Type.FIXED_DECIMAL` value.
_isFDInst(T)True for any `FixedDecimal` instantiation.
_nativeKindOf(T)Maps a (possibly const/immutable-qualified) element type to its kind.
_isSharedQualified(T)True when `T` carries the `shared` qualifier (including shared-const forms).
_isNativeSlice(T)True for dynamic arrays of whitelisted native element types.
_isNativeView(T)True for `const(E)[]` views over whitelisted native element types.
_nativeViewElem(T)Element type of a native view type `const(E)[]`.
_isBareNativeSlice(T)True for unqualified `E[]` slices of whitelisted native element types.
ElementRangeA forward range over the elements of a `var` array.
ConstElementRangeA forward range over the elements of a `const var` array.
KeyRangeA forward range over the keys of a `var` object.
ValueRangeA forward range over the values of a `var` object.
KeyValuePairA key-value pair returned by `PairRange`.
PairRangeA forward range over the key-value pairs of a `var` object.
_PutAdapterNormalizes a sink that provides either put capability to one that provides both.