Struct base::SharedMemory

source ·
pub struct SharedMemory {
    pub descriptor: SafeDescriptor,
    pub size: u64,
}
Expand description

A shared memory file descriptor and its size.

Fields§

§descriptor: SafeDescriptor§size: u64

Implementations§

source§

impl SharedMemory

source

pub fn new<T: Into<Vec<u8>>>(debug_name: T, size: u64) -> Result<SharedMemory>

Creates a new shared memory object of the given size.

|name| is purely for debugging purposes. It does not need to be unique, and it does not affect any non-debugging related properties of the constructed shared memory.

source

pub fn size(&self) -> u64

Gets the size in bytes of the shared memory.

The size returned here does not reflect changes by other interfaces or users of the shared memory file descriptor.

source

pub fn from_safe_descriptor( descriptor: SafeDescriptor, size: u64 ) -> Result<SharedMemory>

Creates a SharedMemory instance from a SafeDescriptor owning a reference to a shared memory descriptor. Ownership of the underlying descriptor is transferred to the new SharedMemory object.

source

pub fn try_clone(&self) -> Result<SharedMemory>

Clones the SharedMemory. The new SharedMemory will refer to the same underlying object as the original.

Trait Implementations§

source§

impl AsRawDescriptor for SharedMemory

USE THIS CAUTIOUSLY. On Windows, the returned handle is not a file handle and cannot be used as if it were one. It is a handle to a the associated file mapping object and should only be used for memory-mapping the file view.

source§

fn as_raw_descriptor(&self) -> RawDescriptor

Returns the underlying raw descriptor. Read more
source§

impl Debug for SharedMemory

source§

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

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for SharedMemory

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl From<SharedMemory> for SafeDescriptor

source§

fn from(sm: SharedMemory) -> SafeDescriptor

Converts to this type from the input type.
source§

impl PlatformSharedMemory for SharedMemory

source§

fn new(debug_name: &CStr, size: u64) -> Result<SharedMemory>

Creates a new shared memory file descriptor with the specified size in bytes.

name will appear in /proc/self/fd/<shm fd> for the purposes of debugging. The name does not need to be unique.

The file descriptor is opened with the close on exec flag and allows memfd sealing.

If the MFD_NOEXEC_SEAL flag is supported, the resulting file will also be created with a non-executable file mode (in other words, it cannot be passed to the exec family of system calls).

source§

fn from_safe_descriptor( descriptor: SafeDescriptor, size: u64 ) -> Result<SharedMemory>

Creates a SharedMemory instance from a SafeDescriptor owning a reference to a shared memory descriptor. Ownership of the underlying descriptor is transferred to the new SharedMemory object.

source§

impl Serialize for SharedMemory

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl SharedMemory for SharedMemory

§

type Error = Error

source§

fn anon(size: u64) -> Result<Self>

Creates a new shared memory file descriptor without specifying a name.
source§

fn size(&self) -> u64

Gets the size in bytes of the shared memory. Read more
source§

fn as_raw_fd(&self) -> RawDescriptor

Returns the underlying raw fd.
source§

impl SharedMemoryLinux for SharedMemory

source§

fn from_file(file: File) -> Result<SharedMemory>

Constructs a SharedMemory instance from a File that represents shared memory. Read more
source§

fn get_seals(&self) -> Result<MemfdSeals>

Gets the memfd seals that have already been added to this. Read more
source§

fn add_seals(&mut self, seals: MemfdSeals) -> Result<()>

Adds the given set of memfd seals. Read more

Auto Trait Implementations§

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> AsRawDescriptors for T
where T: AsRawDescriptor,

source§

fn as_raw_descriptors(&self) -> Vec<i32>

Returns the underlying raw descriptors. 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>,

§

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>,

§

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.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,