sigma_types

Struct Sigma

Source
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>

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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).

Source

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).

Source

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.

Source

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.

Source

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.

Source

pub fn try_check(&self) -> Result<(), Invariant::Error<'_>>

Check an invariant without panicking.

§Errors

If the invariant does not hold.

Source

pub fn try_new(raw: Raw) -> Option<Self>

Create a new sigma type instance by checking an invariant.

§Errors

If the invariant does not hold.

Trait Implementations§

Source§

impl<Raw: Debug, Invariant: Test<Raw, 1>> AsRef<Raw> for Sigma<Raw, Invariant>

Source§

fn as_ref(&self) -> &Raw

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<Raw: Debug, Invariant: Test<Raw, 1>> Borrow<Raw> for Sigma<Raw, Invariant>

Source§

fn borrow(&self) -> &Raw

Immutably borrows from an owned value. Read more
Source§

impl<Raw: Clone + Debug, Invariant: Test<Raw, 1>> Clone for Sigma<Raw, Invariant>

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Raw: Debug, Invariant: Test<Raw, 1>> Debug for Sigma<Raw, Invariant>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Raw: Default + Debug, Invariant: Test<Raw, 1>> Default for Sigma<Raw, Invariant>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<Raw: Debug, Invariant: Test<Raw, 1>> Deref for Sigma<Raw, Invariant>

Source§

type Target = Raw

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<Raw: Debug + Display, Invariant: Test<Raw, 1>> Display for Sigma<Raw, Invariant>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Raw: Hash + Debug, Invariant: Test<Raw, 1>> Hash for Sigma<Raw, Invariant>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
Source§

fn hash_slice<H: Hasher>(data: &[Self], state: &mut H)

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<Raw: Ord + Debug, Invariant: Test<Raw, 1>> Ord for Sigma<Raw, Invariant>

Source§

fn clamp(self, min: Self, max: Self) -> Self

Restrict a value to a certain interval. Read more
Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
Source§

fn max(self, other: Self) -> Self

Compares and returns the maximum of two values. Read more
Source§

fn min(self, other: Self) -> Self

Compares and returns the minimum of two values. Read more
Source§

impl<Raw: PartialEq + Debug, Invariant: Test<Raw, 1>> PartialEq for Sigma<Raw, Invariant>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
Source§

fn ne(&self, other: &Self) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<Raw: PartialOrd + Debug, Invariant: Test<Raw, 1>> PartialOrd for Sigma<Raw, Invariant>

Source§

fn ge(&self, other: &Self) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

fn gt(&self, other: &Self) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
Source§

fn le(&self, other: &Self) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
Source§

fn lt(&self, other: &Self) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
Source§

impl<Raw: Copy + Debug, Invariant: Test<Raw, 1>> Copy for Sigma<Raw, Invariant>

Source§

impl<Raw: Eq + Debug, Invariant: Test<Raw, 1>> Eq for Sigma<Raw, Invariant>

Auto Trait Implementations§

§

impl<Raw, Invariant> Freeze for Sigma<Raw, Invariant>
where Raw: Freeze,

§

impl<Raw, Invariant> RefUnwindSafe for Sigma<Raw, Invariant>
where Raw: RefUnwindSafe, Invariant: RefUnwindSafe,

§

impl<Raw, Invariant> Send for Sigma<Raw, Invariant>
where Raw: Send, Invariant: Send,

§

impl<Raw, Invariant> Sync for Sigma<Raw, Invariant>
where Raw: Sync, Invariant: Sync,

§

impl<Raw, Invariant> Unpin for Sigma<Raw, Invariant>
where Raw: Unpin, Invariant: Unpin,

§

impl<Raw, Invariant> UnwindSafe for Sigma<Raw, Invariant>
where Raw: UnwindSafe, Invariant: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.