Skip to main content

Shared

Struct Shared 

Source
pub struct Shared<T> { /* private fields */ }
Expand description

A wrapper for data that can be shared across processes.

The data is owned, but the element of type T will not be dropped when the Shared<T> is dropped. Note that an element that has a meaningful Drop is likely not ProcSync anyway.

Implementations§

Source§

impl<T> Shared<T>

Source

pub fn new(val: T) -> Result<Shared<T>, Error>

Creates and initializes a Shared<T> to value val.

Source§

impl Shared<c_void>

Source

pub fn new_sized(size: usize) -> Result<Shared<c_void>, Error>

Creates a Shared<c_void> that points to a memory region of size size, aligned to page boundary.

Proper handling of the returned value is left up to the user.

Source§

impl<T> Shared<T>

Source

pub fn try_clone(data: &Shared<T>) -> Result<Shared<T>, Error>

Attempts to clone data.

This will remap data at another location in memory, in addition to keeping data alive.

Source

pub fn as_mut_ptr(data: &Shared<T>) -> *mut T

Returns a mutable pointer to the data contained by data.

Note that using this pointer needs the caller to handle synchronization themselves.

Source

pub fn size(data: &Shared<T>) -> usize

Returns the size in bytes of the data contained by data.

For a Shared<T> it is mem::size_of<T>() and for Shared<c_void> it is the size specified at creation.

Source§

impl<T: ProcSync> Shared<T>

Source

pub unsafe fn from_raw_fd(fd: RawFd) -> Result<Shared<T>, Error>

Creates a Shared<T> from pre-existing fd.

§Safety

This assumes that fd is a file descriptor that has been created by another instance of Shared<T>, and that it will never be used by anything else than Shared<T>. Note that not respecting this will at best do as bad as std::mem::transmute, and at worst end in tears.

This also assumes that fd is not shared with another Shared<T>, as the output of as_raw_fd() is only a borrow. Do not forget to call dup before passing the file descriptor to from_raw_fd if you are not using into_raw_fd and have not passed the RawFd over a socket.

Trait Implementations§

Source§

impl<T> AsRawFd for Shared<T>

Source§

fn as_raw_fd(&self) -> RawFd

Extracts the raw file descriptor. Read more
Source§

impl<T> Deref for Shared<T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &T

Dereferences the value.
Source§

impl<T> Drop for Shared<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T> IntoRawFd for Shared<T>

Source§

fn into_raw_fd(self) -> RawFd

Consumes this object, returning the raw underlying file descriptor. Read more
Source§

impl<T: Sync> Send for Shared<T>

Source§

impl<T: Sync> Sync for Shared<T>

Auto Trait Implementations§

§

impl<T> Freeze for Shared<T>

§

impl<T> RefUnwindSafe for Shared<T>
where T: RefUnwindSafe,

§

impl<T> Unpin for Shared<T>

§

impl<T> UnsafeUnpin for Shared<T>

§

impl<T> UnwindSafe for Shared<T>
where T: RefUnwindSafe,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.