pub struct FracGhost<T> { /* private fields */ }Expand description
An implementation of a resource for fractional ownership of a ghost variable.
If you just want to split the permission in half, you can also use the
GhostVar<T> and GhostVarAuth<T> library.
§Example
fn example_use() {
let tracked mut r = FracGhost::<u64>::new(123);
assert(r@ == 123);
assert(r.frac() == 1 as real);
let tracked r2 = r.split();
assert(r@ == 123);
assert(r2@ == 123);
assert(r.frac() == (0.5 as real));
assert(r2.frac() == (0.5 as real));
proof {
r.combine(r2);
r.update(456);
}
assert(r@ == 456);
assert(r.frac() == 3 as real);
let tracked mut a = FracGhost::<u32>::new(5);
assert(a@ == 5);
assert(a.frac() == 1real);
let tracked mut b = a.split();
assert(a.frac() == (0.5 as real));
assert(b.frac() == (0.5 as real));
proof {
a.update_with(&mut b, 123);
}
assert(a@ == 123);
proof {
a.combine(b);
a.update(6);
}
assert(a@ == 6);
}Implementations§
Source§impl<T> FracGhost<T>
impl<T> FracGhost<T>
Sourcepub open spec fn valid(self, id: Loc, frac: real) -> bool
pub open spec fn valid(self, id: Loc, frac: real) -> bool
{
&&& self.id() == id
&&& self.frac() == frac
}Sourcepub proof fn new(v: T) -> tracked result : Self
pub proof fn new(v: T) -> tracked result : Self
result.frac() == 1 as real,result@ == v,Allocate a new resource with the given value.
Sourcepub proof fn agree(tracked &self, tracked other: &Self)
pub proof fn agree(tracked &self, tracked other: &Self)
self.id() == other.id(),ensuresself@ == other@,Two resources agree on their values.
Sourcepub proof fn take(tracked &mut self) -> tracked result : Self
pub proof fn take(tracked &mut self) -> tracked result : Self
result == *old(self),Take a token out of a mutable reference, leaving a meaningless token behind.
Sourcepub proof fn split_to(tracked &mut self, result_frac: real) -> tracked result : Self
pub proof fn split_to(tracked &mut self, result_frac: real) -> tracked result : Self
(0 as real) < result_frac < old(self).frac(),ensuresfinal(self).id() == old(self).id(),result.id() == final(self).id(),final(self)@ == old(self)@,result@ == old(self)@,final(self).frac() == old(self).frac() - result_frac,result.frac() == result_frac,Split one resource into two. Both the returned resource and self have half of the original fraction.
Sourcepub proof fn split(tracked &mut self) -> tracked result : Self
pub proof fn split(tracked &mut self) -> tracked result : Self
final(self).id() == old(self).id(),result.id() == final(self).id(),final(self)@ == old(self)@,result@ == old(self)@,final(self).frac() == old(self).frac() / 2 as real,result.frac() == old(self).frac() / 2 as real,Split one resource into two. Both the returned resource and self have half of the original fraction.
Sourcepub proof fn combine(tracked &mut self, tracked other: Self)
pub proof fn combine(tracked &mut self, tracked other: Self)
old(self).id() == other.id(),ensuresfinal(self).id() == old(self).id(),final(self)@ == old(self)@,final(self)@ == other@,final(self).frac() == old(self).frac() + other.frac(),Combine two resources, summing their quantities.
Sourcepub proof fn update(tracked &mut self, v: T)
pub proof fn update(tracked &mut self, v: T)
old(self).frac() == (1 as real),ensuresfinal(self).id() == old(self).id(),final(self)@ == v,final(self).frac() == old(self).frac(),Update the value of the resource. This requires having ALL the permissions,
Sourcepub proof fn update_with(tracked &mut self, tracked other: &mut Self, v: T)
pub proof fn update_with(tracked &mut self, tracked other: &mut Self, v: T)
old(self).id() == old(other).id(),old(self).frac() + old(other).frac() == 1 as real,ensuresfinal(self).id() == old(self).id(),final(other).id() == old(other).id(),final(self).frac() == old(self).frac(),final(other).frac() == old(other).frac(),old(self)@ == old(other)@,final(self)@ == v,final(other)@ == v,Update the value of the token. This requires having ALL the permissions (i.e., a fractional authority of 1),
Auto Trait Implementations§
impl<T> Freeze for FracGhost<T>
impl<T> RefUnwindSafe for FracGhost<T>where
T: RefUnwindSafe,
impl<T> Send for FracGhost<T>where
T: Send,
impl<T> Sync for FracGhost<T>where
T: Sync,
impl<T> Unpin for FracGhost<T>where
T: Unpin,
impl<T> UnsafeUnpin for FracGhost<T>
impl<T> UnwindSafe for FracGhost<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
Source§impl<T, U> IntoSpecImpl<U> for Twhere
U: From<T>,
impl<T, U> IntoSpecImpl<U> for Twhere
U: From<T>,
Source§impl<T, VERUS_SPEC__A> TryFromSpec<T> for VERUS_SPEC__Awhere
VERUS_SPEC__A: TryFrom<T>,
impl<T, VERUS_SPEC__A> TryFromSpec<T> for VERUS_SPEC__Awhere
VERUS_SPEC__A: TryFrom<T>,
Source§exec fn obeys_try_from_spec() -> bool
exec fn obeys_try_from_spec() -> bool
Source§impl<T, VERUS_SPEC__A> TryIntoSpec<T> for VERUS_SPEC__Awhere
VERUS_SPEC__A: TryInto<T>,
impl<T, VERUS_SPEC__A> TryIntoSpec<T> for VERUS_SPEC__Awhere
VERUS_SPEC__A: TryInto<T>,
Source§exec fn obeys_try_into_spec() -> bool
exec fn obeys_try_into_spec() -> bool
Source§impl<T, U> TryIntoSpecImpl<U> for Twhere
U: TryFrom<T>,
impl<T, U> TryIntoSpecImpl<U> for Twhere
U: TryFrom<T>,
Source§open spec fn obeys_try_into_spec() -> bool
open spec fn obeys_try_into_spec() -> bool
{ <U as TryFromSpec<Self>>::obeys_try_from_spec() }