pub struct Sigma<Raw: Debug, Invariant: Test<Raw, 1>> { /* private fields */ }
Expand description
Type that maintains a given invariant.
Implementations§
Source§impl<Raw: Debug, Invariant: Test<Raw, 1>> Sigma<Raw, Invariant>
impl<Raw: Debug, Invariant: Test<Raw, 1>> Sigma<Raw, Invariant>
Sourcepub fn also<OtherInvariant: Test<Raw, 1>>(&self) -> &Sigma<Raw, OtherInvariant>
pub fn also<OtherInvariant: Test<Raw, 1>>(&self) -> &Sigma<Raw, OtherInvariant>
Without changing its internal value, view one sigma-typed value as implementing another sigma type by checking the latter invariant at runtime (iff debug assertions are enabled).
§Panics
If the latter invariant does not hold.
Sourcepub fn check(&self)
pub fn check(&self)
Check an invariant if and only if debug assertions are enabled.
§Panics
If the invariant does not hold and debug assertions are enabled.
Sourcepub fn get(self) -> Raw
pub fn get(self) -> Raw
Unwrap the internal value that satisfies the invariant.
If you’re using this to create another value that should
also maintain an invariant, use map
instead.
Sourcepub fn get_by<Y, F: FnOnce(Raw) -> Y>(self, f: F) -> Y
pub fn get_by<Y, F: FnOnce(Raw) -> Y>(self, f: F) -> Y
Unwrap the internal value that satisfies the invariant.
If you’re using this to create another value that should
also maintain an invariant, use map
instead.
Sourcepub fn get_by_mut<Y, F: FnOnce(&mut Raw) -> Y>(&mut self, f: F) -> Y
pub fn get_by_mut<Y, F: FnOnce(&mut Raw) -> Y>(&mut self, f: F) -> Y
Unwrap the internal value that satisfies the invariant.
If you’re using this to create another value that should
also maintain an invariant, use map
instead.
Sourcepub fn get_by_ref<Y, F: FnOnce(&Raw) -> Y>(&self, f: F) -> Y
pub fn get_by_ref<Y, F: FnOnce(&Raw) -> Y>(&self, f: F) -> Y
Unwrap the internal value that satisfies the invariant.
If you’re using this to create another value that should
also maintain an invariant, use map
instead.
Sourcepub const fn get_mut(&mut self) -> &mut Raw
pub const fn get_mut(&mut self) -> &mut Raw
Unwrap the internal value that satisfies the invariant.
If you’re using this to create another value that should
also maintain an invariant, use map
instead.
Sourcepub fn map<OtherRaw: Debug, OtherInvariant: Test<OtherRaw, 1>, F: FnOnce(Raw) -> OtherRaw>(
self,
f: F,
) -> Sigma<OtherRaw, OtherInvariant>
pub fn map<OtherRaw: Debug, OtherInvariant: Test<OtherRaw, 1>, F: FnOnce(Raw) -> OtherRaw>( self, f: F, ) -> Sigma<OtherRaw, OtherInvariant>
Apply a function to a term that implements a given invariant (say, A), then check the output for a (possibly different) invariant (say, B).
Sourcepub fn map_ref<OtherRaw: Debug, OtherInvariant: Test<OtherRaw, 1>, F: FnOnce(&Raw) -> OtherRaw>(
&self,
f: F,
) -> Sigma<OtherRaw, OtherInvariant>
pub fn map_ref<OtherRaw: Debug, OtherInvariant: Test<OtherRaw, 1>, F: FnOnce(&Raw) -> OtherRaw>( &self, f: F, ) -> Sigma<OtherRaw, OtherInvariant>
Apply a function to a term that implements a given invariant (say, A), then check the output for a (possibly different) invariant (say, B).
Sourcepub fn modify<Y, F: FnOnce(&mut Raw) -> Y>(&mut self, f: F) -> Y
pub fn modify<Y, F: FnOnce(&mut Raw) -> Y>(&mut self, f: F) -> Y
Apply a function that mutates this value, then check that the operation maintained this invariant.
Sourcepub fn new(raw: Raw) -> Self
pub fn new(raw: Raw) -> Self
Create a new sigma type instance by checking an invariant.
§Panics
If the invariant does not hold and debug assertions are enabled.
Sourcepub fn try_also<OtherInvariant: Test<Raw, 1>>(
&self,
) -> Result<&Sigma<Raw, OtherInvariant>, OtherInvariant::Error<'_>>
pub fn try_also<OtherInvariant: Test<Raw, 1>>( &self, ) -> Result<&Sigma<Raw, OtherInvariant>, OtherInvariant::Error<'_>>
Without changing its internal value, try to view one sigma-typed value as implementing another sigma type by checking the latter invariant at runtime.
§Errors
If the latter invariant does not hold.