Struct creusot_contracts::ptr_own::PtrOwn
source · pub struct PtrOwn<T: ?Sized>(/* private fields */);
Expand description
Token that represents the ownership of a memory cell. A PtrOwn
value only
exists in the ghost world, but can be used in combination with a
corresponding RawPtr
to access and modify memory.
A warning regarding memory leaks: dropping a GhostBox<PtrOwn<T>>
(we only
ever handle ghost PtrOwn
values) cannot deallocate the memory
corresponding to the pointer because it is a ghost value. One must thus
remember to explicitly call drop
in order to free the memory tracked by a
PtrOwn
token.
Implementations§
source§impl<T: ?Sized> PtrOwn<T>
impl<T: ?Sized> PtrOwn<T>
sourcepub fn as_ref(ptr: RawPtr<T>, own: GhostBox<&PtrOwn<T>>) -> &T
pub fn as_ref(ptr: RawPtr<T>, own: GhostBox<&PtrOwn<T>>) -> &T
Immutably borrows the underlying T
.
requires
ptr == own.ptr()
ensures
*result == *own.val()
sourcepub fn as_mut(ptr: RawPtr<T>, own: GhostBox<&mut PtrOwn<T>>) -> &mut T
pub fn as_mut(ptr: RawPtr<T>, own: GhostBox<&mut PtrOwn<T>>) -> &mut T
Mutably borrows the underlying T
.
requires
ptr == own.ptr()
ensures
*result == *own.val()
ensures
(^own.inner_logic()).ptr() == own.ptr()
ensures
*(^own.inner_logic()).val() == ^result
sourcepub fn drop(ptr: RawPtr<T>, own: GhostBox<PtrOwn<T>>)
pub fn drop(ptr: RawPtr<T>, own: GhostBox<PtrOwn<T>>)
Deallocates the memory pointed by ptr
.
requires
ptr == own.ptr()
sourcepub fn disjoint_lemma(own1: &mut PtrOwn<T>, own2: &PtrOwn<T>)
pub fn disjoint_lemma(own1: &mut PtrOwn<T>, own2: &PtrOwn<T>)
If one owns two PtrOwn
s in ghost code, then they are for different pointers.
pure
ensures
own1.ptr().addr_logic() != own2.ptr().addr_logic()
ensures
*own1 == ^own1
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for PtrOwn<T>where
T: ?Sized,
impl<T> !RefUnwindSafe for PtrOwn<T>
impl<T> !Send for PtrOwn<T>
impl<T> !Sync for PtrOwn<T>
impl<T> !Unpin for PtrOwn<T>
impl<T> !UnwindSafe for PtrOwn<T>
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> MakeSized for Twhere
T: ?Sized,
impl<T> MakeSized for Twhere
T: ?Sized,
source§fn make_sized(&self) -> Box<T>
fn make_sized(&self) -> Box<T>
logic ⚠
ensures
*result == *self