pub struct Right<A, B, const TOTAL: u64 = 2> { /* private fields */ }Expand description
Right ensures the resource is of type B.
Implementations§
Source§impl<A, B, const TOTAL: u64> Right<A, B, TOTAL>
impl<A, B, const TOTAL: u64> Right<A, B, TOTAL>
Sourcepub closed spec fn protocol_monoid(self) -> SumSP<A, B, TOTAL>
pub closed spec fn protocol_monoid(self) -> SumSP<A, B, TOTAL>
The underlying protocol monoid value for this resource.
Sourcepub open spec fn is_resource_owner(self) -> bool
pub open spec fn is_resource_owner(self) -> bool
{ self.protocol_monoid().is_resource_owner() }Whether this token has the right to access the underlying resource.
Sourcepub open spec fn resource(self) -> B
pub open spec fn resource(self) -> B
{ self.protocol_monoid().resource()->Right_0 }The resource value, only meaningful if is_resource_owner is true.
Sourcepub open spec fn wf(self) -> bool
pub open spec fn wf(self) -> bool
{
&&& self.protocol_monoid().is_right()
&&& self.protocol_monoid().is_valid()
&&& 1 <= self.frac() <= TOTAL
&&& self.is_resource_owner() ==> (self.has_resource() <==> !self.has_no_resource())
}Type invariant.
Sourcepub open spec fn has_resource(self) -> bool
pub open spec fn has_resource(self) -> bool
{ self.protocol_monoid().has_resource() }Whether the resource is currently stored, only meaningful if is_resource_owner is true.
Sourcepub open spec fn has_no_resource(self) -> bool
pub open spec fn has_no_resource(self) -> bool
{ self.protocol_monoid().has_no_resource() }Whether the resource has been taken, only meaningful if is_resource_owner is true.
Sourcepub open spec fn frac(self) -> int
pub open spec fn frac(self) -> int
{ self.protocol_monoid().frac() }The fraction this token represents.
Sourcepub proof fn validate(tracked &self)
pub proof fn validate(tracked &self)
self.wf(),Right token satisfies the type invariant.
Sourcepub proof fn validate_with_left(tracked &self, tracked other: &Left<A, B, TOTAL>)
pub proof fn validate_with_left(tracked &self, tracked other: &Left<A, B, TOTAL>)
self.id() != other.id(),The existence of a Left token ensures they can not have the same id.
Sourcepub proof fn validate_with_right(tracked &mut self, tracked other: &Self)
pub proof fn validate_with_right(tracked &mut self, tracked other: &Self)
old(self).id() == other.id(),ensures*old(self) == *final(self),!(final(self).is_resource_owner() && other.is_resource_owner()),final(self).frac() + other.frac() <= TOTAL,final(self).wf(),The existence of two Right tokens with the same id ensures at most one of them is the resource owner.
Sourcepub proof fn tracked_borrow(tracked &self) -> tracked res : &B
pub proof fn tracked_borrow(tracked &self) -> tracked res : &B
self.has_resource(),ensures*res == self.resource(),Borrows the resource of type B.
Sourcepub proof fn take_resource(tracked &mut self) -> tracked res : B
pub proof fn take_resource(tracked &mut self) -> tracked res : B
old(self).is_resource_owner(),old(self).has_resource(),ensuresfinal(self).id() == old(self).id(),res == old(self).resource(),final(self).is_resource_owner(),final(self).has_no_resource(),final(self).frac() == old(self).frac(),final(self).wf(),Takes the resource out of the token.
Sourcepub proof fn put_resource(tracked &mut self, tracked b: B)
pub proof fn put_resource(tracked &mut self, tracked b: B)
old(self).is_resource_owner(),old(self).has_no_resource(),ensuresfinal(self).id() == old(self).id(),final(self).protocol_monoid()
== SumSP::<A, B, TOTAL>::Right(Some(b), final(self).frac(), true),final(self).is_resource_owner(),final(self).has_resource(),final(self).resource() == b,final(self).frac() == old(self).frac(),final(self).wf(),Puts a resource of type B back to the token.
Sourcepub proof fn split_with_resource(tracked &mut self, n: int) -> tracked res : Self
pub proof fn split_with_resource(tracked &mut self, n: int) -> tracked res : Self
0 < n < old(self).frac(),ensuresfinal(self).id() == old(self).id(),res.id() == final(self).id(),final(self).frac() == old(self).frac() - n,res.frac() == n,!final(self).is_resource_owner(),res.is_resource_owner() <==> old(self).is_resource_owner(),res.is_resource_owner() ==> (res.has_resource() <==> old(self).has_resource()),res.has_resource() ==> res.resource() == old(self).resource(),final(self).wf(),res.wf(),Splits this token into two Right tokens with the given fraction n, given the resource to the new token if available.
Sourcepub proof fn split_without_resource(tracked &mut self, n: int) -> tracked res : Self
pub proof fn split_without_resource(tracked &mut self, n: int) -> tracked res : Self
0 < n < old(self).frac(),ensuresfinal(self).id() == old(self).id(),res.id() == final(self).id(),final(self).frac() == old(self).frac() - n,res.frac() == n,!res.is_resource_owner(),final(self).is_resource_owner() <==> old(self).is_resource_owner(),final(self).is_resource_owner()
==> (final(self).has_resource() <==> old(self).has_resource()),final(self).has_resource() ==> final(self).resource() == old(self).resource(),final(self).wf(),res.wf(),Splits this token into two Right tokens with the given fraction n, without giving the resource to the new token.
Sourcepub proof fn update(tracked &mut self, tracked b: B) -> tracked res : Option<B>
pub proof fn update(tracked &mut self, tracked b: B) -> tracked res : Option<B>
old(self).is_resource_owner(),ensuresfinal(self).id() == old(self).id(),final(self).is_resource_owner(),final(self).has_resource(),final(self).resource() == b,final(self).frac() == old(self).frac(),res == if old(self).has_resource() { Some(old(self).resource()) } else { None },final(self).wf(),Updates the token with a new resource of type B, and returns the old resource if available.
Auto Trait Implementations§
impl<A, B, const TOTAL: u64> Freeze for Right<A, B, TOTAL>
impl<A, B, const TOTAL: u64> RefUnwindSafe for Right<A, B, TOTAL>where
A: RefUnwindSafe,
B: RefUnwindSafe,
impl<A, B, const TOTAL: u64> Send for Right<A, B, TOTAL>
impl<A, B, const TOTAL: u64> Sync for Right<A, B, TOTAL>
impl<A, B, const TOTAL: u64> Unpin for Right<A, B, TOTAL>
impl<A, B, const TOTAL: u64> UnsafeUnpin for Right<A, B, TOTAL>
impl<A, B, const TOTAL: u64> UnwindSafe for Right<A, B, TOTAL>where
A: UnwindSafe,
B: 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
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T, VERUS_SPEC__A> FromSpec<T> for VERUS_SPEC__Awhere
VERUS_SPEC__A: From<T>,
impl<T, VERUS_SPEC__A> FromSpec<T> for VERUS_SPEC__Awhere
VERUS_SPEC__A: From<T>,
fn obeys_from_spec() -> bool
fn from_spec(v: T) -> VERUS_SPEC__A
§impl<T, VERUS_SPEC__A> IntoSpec<T> for VERUS_SPEC__Awhere
VERUS_SPEC__A: Into<T>,
impl<T, VERUS_SPEC__A> IntoSpec<T> for VERUS_SPEC__Awhere
VERUS_SPEC__A: Into<T>,
fn obeys_into_spec() -> bool
fn into_spec(self) -> T
§impl<T, U> IntoSpecImpl<U> for Twhere
U: From<T>,
impl<T, U> IntoSpecImpl<U> for Twhere
U: From<T>,
fn obeys_into_spec() -> bool
fn into_spec(self) -> U
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.impl<A> SpecEq<&A> for Awhere
A: ?Sized,
impl<A> SpecEq<&mut A> for Awhere
A: ?Sized,
impl<A> SpecEq<A> for Awhere
A: ?Sized,
impl<A> SpecEq<Ghost<A>> for A
impl<A> SpecEq<Tracked<A>> for A
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.