Struct imprint::Val
[−]
[src]
pub struct Val<'x, T> { /* fields omitted */ }
A value imprinted at the type level.
A Val<'x, T>
value contains an instance of T
as well as a marker
'x
that reflects the value of that instance at the type level. This
provides a type-safe mechanism to constrain values even if their actual
values are not known at compile time.
Val
can be constructed using either imprint(...)
or
Default::default()
.
The underlying value can be obtained either by dererefencing or by calling
.into_inner()
.
Properties
The notion of "value" is determined by the equivalence relation formed by
Eq
, or the partial equivalence relation formed by PartialEq
.
We expect the value of T
must be immutable through &T
. Otherwise, the
properties in this section would not hold. Therefore, Val
is not very
useful for types with interior mutability like Cell
or RefCell
.
Moreover, keep in mind that any unsafe code can violate these properties
as well.
If
T
forms an equivalence relation, then for every marker'x
, the typeVal<'x, T>
contains precisely one value, and each value corresponds to a unique'x
. Hence,Val<'x, T>
may be considered a singleton type (unrelated to "singletons" in OOP).On the other hand, if
T
forms a partial equivalence relation, then for every marker'x
, the typeVal<'x, T>
contains either a single identifiable value (for which equality is reflexive), or a single unidentifiable value (one for which equality is nonreflexive), and each identifiable value corresponds to a unique marker'x
.
Methods
impl<'x, T> Val<'x, T>
[src]
impl<'x, T: PartialEq> Val<'x, T>
[src]
fn eq<'y>(&self, other: &Val<'y, T>) -> Option<TyEq<Self, Val<'y, T>>>
Checks whether two values are equal. If they are, evidence of their equality is returned.
Trait Implementations
impl<'x, T: Clone> Clone for Val<'x, T>
[src]
fn clone(&self) -> Val<'x, T>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl<'x, T: Copy> Copy for Val<'x, T>
[src]
impl<'x, T: Eq> Eq for Val<'x, T>
[src]
impl<'x, T: PartialEq> PartialEq for Val<'x, T>
[src]
fn eq(&self, __arg_0: &Val<'x, T>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Val<'x, T>) -> bool
This method tests for !=
.
impl<'x, T: Ord> Ord for Val<'x, T>
[src]
fn cmp(&self, __arg_0: &Val<'x, T>) -> Ordering
This method returns an Ordering
between self
and other
. Read more
impl<'x, T: PartialOrd> PartialOrd for Val<'x, T>
[src]
fn partial_cmp(&self, __arg_0: &Val<'x, T>) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, __arg_0: &Val<'x, T>) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, __arg_0: &Val<'x, T>) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, __arg_0: &Val<'x, T>) -> bool
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, __arg_0: &Val<'x, T>) -> bool
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl<'x, T: Hash> Hash for Val<'x, T>
[src]
fn hash<__HT: Hasher>(&self, __arg_0: &mut __HT)
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl<'x, T: Debug> Debug for Val<'x, T>
[src]
impl<T: Default> Default for Val<'static, T>
[src]
The default value always has the special marker of 'static
.
impl<'x, T> AsRef<T> for Val<'x, T>
[src]
fn as_ref(&self) -> &T
Performs the conversion.
impl<'x, T> Borrow<T> for Val<'x, T>
[src]
impl<'x, T> Deref for Val<'x, T>
[src]
type Target = T
The resulting type after dereferencing
fn deref(&self) -> &T
The method called to dereference a value
impl<'x, T> IntoInner for Val<'x, T>
[src]
fn into_inner(self) -> Self::Target
Extracts the inner value.