pub struct ContiguousEntryRef<T: ?Sized> { /* private fields */ }
Expand description
A thread-unsafe reference to T
data stored in
ContiguousMemoryStorage
structure.
Implementations§
Source§impl<T: ?Sized> ContiguousEntryRef<T>
impl<T: ?Sized> ContiguousEntryRef<T>
Sourcepub fn range(&self) -> ByteRange
pub fn range(&self) -> ByteRange
Returns a byte range within container memory this reference points to.
Sourcepub fn get(&self) -> MemoryReadGuard<'_, T, ImplDefault>where
T: RefSizeReq,
pub fn get(&self) -> MemoryReadGuard<'_, T, ImplDefault>where
T: RefSizeReq,
Returns a reference to data at its current location and panics if the represented memory region is mutably borrowed.
Sourcepub fn try_get(
&self,
) -> Result<MemoryReadGuard<'_, T, ImplDefault>, RegionBorrowedError>where
T: RefSizeReq,
pub fn try_get(
&self,
) -> Result<MemoryReadGuard<'_, T, ImplDefault>, RegionBorrowedError>where
T: RefSizeReq,
Returns a reference to data at its current location or a
RegionBorrowedError
error if the represented memory region is
mutably borrowed.
Sourcepub fn get_mut(&mut self) -> MemoryWriteGuard<'_, T, ImplDefault>where
T: RefSizeReq,
pub fn get_mut(&mut self) -> MemoryWriteGuard<'_, T, ImplDefault>where
T: RefSizeReq,
Returns a mutable reference to data at its current location and panics if the reference has already been borrowed.
Sourcepub fn try_get_mut(
&mut self,
) -> Result<MemoryWriteGuard<'_, T, ImplDefault>, RegionBorrowedError>where
T: RefSizeReq,
pub fn try_get_mut(
&mut self,
) -> Result<MemoryWriteGuard<'_, T, ImplDefault>, RegionBorrowedError>where
T: RefSizeReq,
Returns a mutable reference to data at its current location or a
RegionBorrowedError
error if the represented memory region is
already borrowed.
Sourcepub fn into_dyn<R: ?Sized>(self) -> ContiguousEntryRef<R>
Available on crate feature ptr_metadata
only.
pub fn into_dyn<R: ?Sized>(self) -> ContiguousEntryRef<R>
ptr_metadata
only.Casts this reference into a dynamic type R
.
Sourcepub fn downcast_dyn<R: Unsize<T>>(self) -> Option<ContiguousEntryRef<R>>
Available on crate feature ptr_metadata
only.
pub fn downcast_dyn<R: Unsize<T>>(self) -> Option<ContiguousEntryRef<R>>
ptr_metadata
only.Tries downcasting this dynamic reference into a discrete type R
,
returns None if R
drop handler doesn’t match the original one.
Sourcepub unsafe fn with_metadata<R: ?Sized>(
self,
metadata: <R as Pointee>::Metadata,
) -> ContiguousEntryRef<R>
Available on crate feature ptr_metadata
only.
pub unsafe fn with_metadata<R: ?Sized>( self, metadata: <R as Pointee>::Metadata, ) -> ContiguousEntryRef<R>
ptr_metadata
only.Transmutes this reference to type R
with provided metadata
.
static_metadata
function may be used to
statically construct metadata for a struct-trait pair.
§Safety
This function is unsafe because it assumes any T
to implement R
,
as the original type of stored data can be erased through
into_dyn
it’s impossible to check
whether the initial struct actually implements R
.
Calling methods from an incorrect vtable will cause undefined behavior.
Sourcepub unsafe fn as_ptr(&self) -> *const Twhere
T: RefSizeReq,
pub unsafe fn as_ptr(&self) -> *const Twhere
T: RefSizeReq,
Creates an immutable pointer to underlying data.
§Safety
This function returns a pointer that may become invalid if the container’s memory is resized to a capacity which requires the memory segment to be moved.
When the reference goes out of scope, its region will be marked as free
which means that a subsequent call to ContiguousMemoryStorage::push
or friends can cause undefined behavior when dereferencing the pointer.
Sourcepub unsafe fn as_ptr_mut(&self) -> *mut Twhere
T: RefSizeReq,
pub unsafe fn as_ptr_mut(&self) -> *mut Twhere
T: RefSizeReq,
Creates a mutable pointer to underlying data.
§Safety
In addition to concerns noted in ContiguousEntryRef::as_ptr
,
this function also provides mutable access to the underlying data
allowing potential data races.
Sourcepub unsafe fn into_ptr(self) -> *const Twhere
T: RefSizeReq,
pub unsafe fn into_ptr(self) -> *const Twhere
T: RefSizeReq,
Creates an immutable pointer to underlying data while also preventing the occupied memory region from being marked as free.
§Safety
This function returns a pointer that may become invalid if the container’s memory is resized to a capacity which requires the memory segment to be moved.
Sourcepub unsafe fn into_ptr_mut(self) -> *mut Twhere
T: RefSizeReq,
pub unsafe fn into_ptr_mut(self) -> *mut Twhere
T: RefSizeReq,
Creates a mutable pointer to underlying data while also preventing the occupied memory region from being marked as free.
§Safety
In addition to concerns noted in
ContiguousEntryRef::into_ptr
, this function also provides
mutable access to the underlying data allowing potential data races.