pub struct GhostMapAuth<K, V> { /* private fields */ }
Implementations§
Source§impl<K, V> GhostMapAuth<K, V>
An implementation of a resource for owning a subset of keys in a map.
impl<K, V> GhostMapAuth<K, V>
An implementation of a resource for owning a subset of keys in a map.
GhostMapAuth<K, T>
represents authoritative ownership of the entire
map, and GhostSubmap<K, T>
represents client ownership of some subset
of keys in the map. Updating the authoritative GhostMapAuth<K, T>
requires a GhostSubmap<K, T>
containing the keys being updated.
GhostSubmap<K, T>
s can be combined or split.
§Example
fn example_use() {
let tracked (mut auth, mut sub) = GhostMapAuth::new(map![1u8 => 1u64, 2u8 => 2u64, 3u8 => 3u64]);
// Allocate some more keys in the auth map, receiving a new submap.
let tracked sub2 = auth.insert(map![4u8 => 4u64, 5u8 => 5u64]);
proof { sub.combine(sub2); }
// Delete some keys in the auth map, by returning corresponding submap.
let tracked sub3 = sub.split(set![3u8, 4u8]);
proof { auth.delete(sub3); }
// Split the submap into a multiple submaps.
let tracked sub4 = sub.split(set![1u8, 5u8]);
// In general, we might need to call agree() to establish the fact that
// a submap has the same values as the auth map. Here, Verus doesn't need
// agree because it can track where both the auth and submap came from.
proof { sub.agree(&auth); }
proof { sub4.agree(&auth); }
assert(sub4[1u8] == auth[1u8]);
assert(sub4[5u8] == auth[5u8]);
assert(sub[2u8] == auth[2u8]);
// Update keys using ownership of submaps.
proof { sub.update(&mut auth, map![2u8 => 22u64]); }
proof { sub4.update(&mut auth, map![1u8 => 11u64]); }
assert(auth[1u8] == 11u64);
assert(auth[2u8] == 22u64);
// Not shown in this simple example is the main use case of this resource:
// maintaining an invariant between GhostMapAuth<K, V> and some exec-mode
// shared state with a map view (e.g., HashMap<K, V>), which states that
// the Map<K, V> view of GhostMapAuth<K, V> is the same as the view of the
// HashMap<K, V>, and then handing out a GhostSubmap<K, V> to different
// clients that might need to operate on different keys in this map.
}
Sourcepub open spec fn spec_index(self, key: K) -> V
pub open spec fn spec_index(self, key: K) -> V
recommends
self.dom().contains(key),
{ self@[key] }
Sourcepub proof fn dummy() -> tracked result : GhostMapAuth<K, V>
pub proof fn dummy() -> tracked result : GhostMapAuth<K, V>
Sourcepub proof fn take(tracked &mut self) -> tracked result : GhostMapAuth<K, V>
pub proof fn take(tracked &mut self) -> tracked result : GhostMapAuth<K, V>
ensures
result == *old(self),
Sourcepub proof fn empty(tracked &self) -> tracked result : GhostSubmap<K, V>
pub proof fn empty(tracked &self) -> tracked result : GhostSubmap<K, V>
ensures
result.id() == self.id(),
result@ == Map::<K, V>::empty(),
Sourcepub proof fn insert(tracked &mut self, m: Map<K, V>) -> tracked result : GhostSubmap<K, V>
pub proof fn insert(tracked &mut self, m: Map<K, V>) -> tracked result : GhostSubmap<K, V>
requires
old(self)@.dom().disjoint(m.dom()),
ensuresself.id() == old(self).id(),
self@ == old(self)@.union_prefer_right(m),
result.id() == self.id(),
result@ == m,
Sourcepub proof fn delete(tracked &mut self, tracked f: GhostSubmap<K, V>)
pub proof fn delete(tracked &mut self, tracked f: GhostSubmap<K, V>)
requires
f.id() == old(self).id(),
ensuresself.id() == old(self).id(),
self@ == old(self)@.remove_keys(f@.dom()),
Sourcepub proof fn new(m: Map<K, V>) -> tracked result : (GhostMapAuth<K, V>, GhostSubmap<K, V>)
pub proof fn new(m: Map<K, V>) -> tracked result : (GhostMapAuth<K, V>, GhostSubmap<K, V>)
ensures
result.0.id() == result.1.id(),
result.0@ == m,
result.1@ == m,
Auto Trait Implementations§
impl<K, V> Freeze for GhostMapAuth<K, V>
impl<K, V> RefUnwindSafe for GhostMapAuth<K, V>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for GhostMapAuth<K, V>
impl<K, V> Sync for GhostMapAuth<K, V>
impl<K, V> Unpin for GhostMapAuth<K, V>
impl<K, V> UnwindSafe for GhostMapAuth<K, V>where
K: UnwindSafe,
V: 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