Struct BorrowedMap

Source
pub struct BorrowedMap<'shm> { /* private fields */ }
Expand description

A wrapper around an memmap2::MmapMut to prevent one from accidentally calling Shm::map twice on the same Shm (which could very easily introduce memory unsoundness). To use the contained map, just call BorrowedMap::map. One cannot safely move the map out of this struct, as that would easily allow them to break the lifetime-dependent relationship between this map and the Shm it’s mapped onto.

To be clear: This risk of memory unsafety does not come from an actual borrowing of memory between the Shm and the MmapMut - a MmapMut can be dropped before or after the Shm which it is mapped from and nothing bad will happen. The issue comes when two MmapMuts are mapped from the same Shm - this could allow e.g. something to borrow from one MmapMut, then the other MmapMut could be shrunk, thus invalidating the references from the first map.

Implementations§

Source§

impl BorrowedMap<'_>

Source

pub fn map(&mut self) -> &mut MmapMut

Source

pub unsafe fn into_map(self) -> MmapMut

Take the inner MmapMut out of this wrapper.

§Safety

This can can unsoundness if another Mmap is created from the Shm that this was derived from. Read the struct-level documentation for more details.

Trait Implementations§

Source§

impl<'shm> Debug for BorrowedMap<'shm>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'shm> Freeze for BorrowedMap<'shm>

§

impl<'shm> RefUnwindSafe for BorrowedMap<'shm>

§

impl<'shm> Send for BorrowedMap<'shm>

§

impl<'shm> Sync for BorrowedMap<'shm>

§

impl<'shm> Unpin for BorrowedMap<'shm>

§

impl<'shm> UnwindSafe for BorrowedMap<'shm>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.