Struct mononym::named::Named [−][src]
pub struct Named<N: HasType<T>, T>(_, _);
Expand description
Represents a named value with a unique type-level name. monoym
guarantees that there can never be two Rust values of the same
type Named<N, T>
. With that, the name type N
can be used to
uniquely identify the underlying value at the type level.
To ensure that functions that are generic over names are well-typed
Named
also requires the name type N
to satisfy the trait bound
HasType<T>
. Although this may introduce more boilerplate,
it also helps programmers to always annotate the type of names
when defining new generic functions.
Implementations
Get a reference to the underlying value of the named value.
mononym
does not provide access to mutable reference to
the underlying value, as mutation may invalidate the proofs
of pre-conditions constructed from the original value.
When using Named
, it is up to the user to ensure that there
is no accidental
interior mutability
provided by the value type T
. Otherwise, user must take
into consideration of the possibility of interior mutability
and ensure that the invariants assumed by the proofs defined
cannot be violated.
Consume the named value and turn it back into the underlying value. After this, the underlying value is no longer associated with the type-level name, and can be safely mutated.
Even though the named value is destroyed, the type-level name can still continue to present in other places such as proof objects. This can be useful for functions that only require proofs about a value, without requiring access to the value itself.