fdf

Struct Message

Source
pub struct Message<T: ?Sized + 'static> { /* private fields */ }
Expand description

A struct that holds both an arena along with a data buffer that is allocated within that arena.

Implementations§

Source§

impl<T: ?Sized> Message<T>

Source

pub fn new<'a>( arena: &'a Arena, data: Option<ArenaBox<'a, T>>, handles: Option<ArenaBox<'a, [Option<MixedHandle>]>>, ) -> Self

Consumes the given arena, data buffer, and handles buffers and returns a message that holds all three.

§Panics

This function panics if either of the ArenaBoxs are not allocated by Arena.

Source

pub fn new_with<F>(arena: Arena, f: F) -> Self
where F: for<'a> FnOnce(&'a Arena) -> (Option<ArenaBox<'a, T>>, Option<ArenaBox<'a, [Option<MixedHandle>]>>),

Given the Arena, allocates a new Message and runs the given f to allow the caller to allocate data and handles into the Message without requiring a check that the correct Arena was used to allocate the data.

Note that it may be possible to sneak an ArenaBox<'static, T> into this Message object with this function by using an Arena with static lifetime to allocate it. This will not cause any unsoundness, but if you try to send that message through a [Channel] it will cause a runtime error when the arenas don’t match.

Source

pub fn new_with_data<F>(arena: Arena, f: F) -> Self
where F: for<'a> FnOnce(&'a Arena) -> ArenaBox<'a, T>,

A shorthand for Self::new_with when there’s definitely a data body and nothing else.

Source

pub fn arena(&self) -> &Arena

Gets a reference to the arena this message was allocated with.

Source

pub fn take_arena(self) -> Arena

Takes the arena and drops any data or handle bodies held in this message

Source

pub fn data(&self) -> Option<&T>

Gets a reference to the data in this message, if there is any

Source

pub fn data_mut(&mut self) -> Option<&mut T>

Gets a mutable reference to the data in this message, if there is any

Source

pub fn map_data<F, R: ?Sized>(self, f: F) -> Message<R>
where F: for<'a> FnOnce(&'a Arena, ArenaBox<'a, T>) -> ArenaBox<'a, R>,

Maps the message data to a new ArenaBox based on the arena and the old data.

Source

pub fn handles(&self) -> Option<&[Option<MixedHandle>]>

Gets a reference to the handles array in this message, if there is one.

Source

pub fn handles_mut(&mut self) -> Option<&mut [Option<MixedHandle>]>

Gets a mutable reference to the handles array in this message, if there is one.

Source

pub fn as_refs(&self) -> (&Arena, Option<&T>, Option<&[Option<MixedHandle>]>)

Gets a reference to all three of the arena, data, and handles of the message

Source

pub fn as_mut_refs( &mut self, ) -> (&Arena, Option<&mut T>, Option<&mut [Option<MixedHandle>]>)

Gets a reference to the arena and mutable references to the data handles of the message

Source

pub fn into_arena_boxes<'a>( self, arena: &'a mut Option<Arena>, ) -> (Option<ArenaBox<'a, T>>, Option<ArenaBox<'a, [Option<MixedHandle>]>>)

Unpacks the arena and buffers in this message to the caller.

The arena argument provides a place to put the Arena from this message in the local lifetime of the caller so that the ArenaBoxes can be tied to its lifetime.

Source

pub fn take_arena_boxes( &mut self, ) -> (&Arena, Option<ArenaBox<'_, T>>, Option<ArenaBox<'_, [Option<MixedHandle>]>>)

Takes the ArenaBoxes for the data and handles from this Message, but leaves the Arena in the Message to act as a holder of the arena lifetime.

Source

pub fn into_raw( self, ) -> (NonNull<fdf_arena_t>, Option<NonNull<T>>, Option<NonNull<[Option<MixedHandle>]>>)

Unpacks the arena and buffers into raw pointers

Care must be taken to ensure that the data and handle pointers are not used if the arena is freed. If they are never reconstituted into a Message or an Arena and ArenaBoxes, they will be leaked.

Source§

impl<T> Message<T>

Source

pub fn take_data(self) -> Option<T>

Takes the data from the message, dropping the Arena and handles array in the process.

Source

pub fn take_data_boxed(self) -> Option<Box<T>>

Takes the data from the message, dropping the Arena and handles array in the process.

Source§

impl<T> Message<[T]>

Source

pub fn take_data_boxed_slice(self) -> Option<Box<[T]>>

Takes the data from the message, dropping the Arena and handles array in the process.

Source§

impl<T> Message<MaybeUninit<T>>

Source

pub unsafe fn assume_init(self) -> Message<T>

Assumes the contents of the data payload of this message are initialized.

§Safety

The caller is responsible for ensuring that the value is initialized properly. See MaybeUninit::assume_init for more details on the safety requirements of this.

Source§

impl<T> Message<[MaybeUninit<T>]>

Source

pub unsafe fn assume_init(self) -> Message<[T]>

Assumes the contents of the data payload of this message are initialized.

§Safety

The caller is responsible for ensuring that the value is initialized properly. See MaybeUninit::assume_init for more details on the safety requirements of this.

Source§

impl Message<[MaybeUninit<u8>]>

Source

pub unsafe fn cast_unchecked<T>(self) -> Message<T>

Transforms the message body into a message of type T

§Safety

The caller is responsible for ensuring that the data portion of this message originated from a source with a properly allocated T with correct alignment

Trait Implementations§

Source§

impl<T: Debug + ?Sized + 'static> Debug for Message<T>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Message<T>
where T: ?Sized,

§

impl<T> RefUnwindSafe for Message<T>
where T: RefUnwindSafe + ?Sized,

§

impl<T> Send for Message<T>
where T: Send + ?Sized,

§

impl<T> Sync for Message<T>
where T: Sync + ?Sized,

§

impl<T> Unpin for Message<T>
where T: Unpin + ?Sized,

§

impl<T> UnwindSafe for Message<T>

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.