pub enum Known<T> {
Known(T),
Unknown,
}Expand description
A value that may not exist yet.
The point of a dedicated type is that Unknown cannot be mistaken for a zero or an
empty string once it reaches a comparison. Combining anything with Unknown yields
Unknown.
Variants§
Implementations§
Source§impl<T> Known<T>
impl<T> Known<T>
Sourcepub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Known<U>
pub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Known<U>
Map the value, keeping Unknown unknown.
Sourcepub fn zip_with<U, R, F: FnOnce(T, U) -> R>(
self,
other: Known<U>,
f: F,
) -> Known<R>
pub fn zip_with<U, R, F: FnOnce(T, U) -> R>( self, other: Known<U>, f: F, ) -> Known<R>
Combine two values; if either is unknown the result is unknown.
use gate_contract::Known;
let a = Known::Known(2);
let b: Known<i32> = Known::Unknown;
assert_eq!(a.zip_with(b, |x, y| x + y), Known::Unknown);Trait Implementations§
impl<T: Copy> Copy for Known<T>
impl<T: Eq> Eq for Known<T>
impl<T: PartialEq> StructuralPartialEq for Known<T>
Auto Trait Implementations§
impl<T> Freeze for Known<T>where
T: Freeze,
impl<T> RefUnwindSafe for Known<T>where
T: RefUnwindSafe,
impl<T> Send for Known<T>where
T: Send,
impl<T> Sync for Known<T>where
T: Sync,
impl<T> Unpin for Known<T>where
T: Unpin,
impl<T> UnsafeUnpin for Known<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for Known<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more