pub struct Subset<T: InhabitedInvariant>(/* private fields */);Expand description
A subset type.
This the same as T, with one exception: the invariant for T will also
be verified in logic.
§Example
struct Pair(i32);
impl Invariant for Pair {
#[logic] fn invariant(self) -> bool { self.0 % 2 == 0 }
}
impl InhabitedInvariant for Pair {
#[logic]
#[ensures(result.invariant())]
fn inhabits() -> Self { Self(0i32) }
}
#[logic]
fn pair_in_logic(x: Subset<Pair>) {
proof_assert!(x.0 % 2 == 0);
}Implementations§
Source§impl<T: InhabitedInvariant> Subset<T>
impl<T: InhabitedInvariant> Subset<T>
Sourcepub fn new_logic(x: T) -> Self
pub fn new_logic(x: T) -> Self
Create a new element of Subset<T> in logic.
As per the documentation of Subset, the returned value will
satisfy T’s type invariant.
(opaque) ⚠
requires
x.invariant()ensures
result@ == xSourcepub fn view_inj(self, other: Self)
pub fn view_inj(self, other: Self)
Characterize that Subset<T> indeed contains a T (and only a T).
§Example
#[requires(x == y@)]
fn foo<T: InhabitedInvariant>(x: T, y: Subset<T>) {
let x = Subset::new(x);
let _ = snapshot!(Subset::<T>::view_inj);
proof_assert!(x == y);
}(opaque) ⚠
requires
self@ == other@ensures
self == otherSourcepub fn new(x: T) -> Self
pub fn new(x: T) -> Self
Create a new element of Subset<T>.
§Example
// Use the `Pair` type defined in `Subset`'s documentation
let p = Subset::new(Pair(0));
proof_assert!(p@.0 == 0i32);terminates
ghost
ensures
result == Self::new_logic(x)Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Unwrap the Subset to get the inner value.
§Example
// Use the `Pair` type defined in `Subset`'s documentation
fn changes_pair(p: &mut Subset<Pair>) { /* ... */ }
let mut p = Subset::new(Pair(0));
changes_pair(&mut p);
let inner = p.into_inner();
proof_assert!(inner.0 % 2 == 0);terminates
ghost
ensures
result == self@Trait Implementations§
Source§impl<T: InhabitedInvariant + DeepModel> DeepModel for Subset<T>
impl<T: InhabitedInvariant + DeepModel> DeepModel for Subset<T>
Source§fn deep_model(self) -> T::DeepModelTy
fn deep_model(self) -> T::DeepModelTy
(inline) ⚠
type DeepModelTy = <T as DeepModel>::DeepModelTy
Source§impl<T: InhabitedInvariant> Deref for Subset<T>
impl<T: InhabitedInvariant> Deref for Subset<T>
Source§impl<T: InhabitedInvariant> DerefMut for Subset<T>
impl<T: InhabitedInvariant> DerefMut for Subset<T>
Source§impl<T: InhabitedInvariant> Resolve for Subset<T>
impl<T: InhabitedInvariant> Resolve for Subset<T>
Source§impl<T: InhabitedInvariant> View for Subset<T>
impl<T: InhabitedInvariant> View for Subset<T>
impl<T: InhabitedInvariant + Copy> Copy for Subset<T>
impl<T: InhabitedInvariant + DeepModel + Eq> Eq for Subset<T>
Auto Trait Implementations§
impl<T> Freeze for Subset<T>where
T: Freeze,
impl<T> RefUnwindSafe for Subset<T>where
T: RefUnwindSafe,
impl<T> Send for Subset<T>where
T: Send,
impl<T> Sync for Subset<T>where
T: Sync,
impl<T> Unpin for Subset<T>where
T: Unpin,
impl<T> UnwindSafe for Subset<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