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>
impl<T: ?Sized> Message<T>
Sourcepub fn new<'a>(
arena: &'a Arena,
data: Option<ArenaBox<'a, T>>,
handles: Option<ArenaBox<'a, [Option<MixedHandle>]>>,
) -> Self
pub fn new<'a>( arena: &'a Arena, data: Option<ArenaBox<'a, T>>, handles: Option<ArenaBox<'a, [Option<MixedHandle>]>>, ) -> Self
Sourcepub fn new_with<F>(arena: Arena, f: F) -> Self
pub fn new_with<F>(arena: Arena, f: F) -> Self
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.
Sourcepub fn new_with_data<F>(arena: Arena, f: F) -> Self
pub fn new_with_data<F>(arena: Arena, f: F) -> Self
A shorthand for Self::new_with
when there’s definitely a data body and nothing else.
Sourcepub fn take_arena(self) -> Arena
pub fn take_arena(self) -> Arena
Takes the arena and drops any data or handle bodies held in this message
Sourcepub fn data_mut(&mut self) -> Option<&mut T>
pub fn data_mut(&mut self) -> Option<&mut T>
Gets a mutable reference to the data in this message, if there is any
Sourcepub fn map_data<F, R: ?Sized>(self, f: F) -> Message<R>
pub fn map_data<F, R: ?Sized>(self, f: F) -> Message<R>
Maps the message data to a new ArenaBox
based on the arena and the old data.
Sourcepub fn handles(&self) -> Option<&[Option<MixedHandle>]>
pub fn handles(&self) -> Option<&[Option<MixedHandle>]>
Gets a reference to the handles array in this message, if there is one.
Sourcepub fn handles_mut(&mut self) -> Option<&mut [Option<MixedHandle>]>
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.
Sourcepub fn as_refs(&self) -> (&Arena, Option<&T>, Option<&[Option<MixedHandle>]>)
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
Sourcepub fn as_mut_refs(
&mut self,
) -> (&Arena, Option<&mut T>, Option<&mut [Option<MixedHandle>]>)
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
Sourcepub fn into_arena_boxes<'a>(
self,
arena: &'a mut Option<Arena>,
) -> (Option<ArenaBox<'a, T>>, Option<ArenaBox<'a, [Option<MixedHandle>]>>)
pub fn into_arena_boxes<'a>( self, arena: &'a mut Option<Arena>, ) -> (Option<ArenaBox<'a, T>>, Option<ArenaBox<'a, [Option<MixedHandle>]>>)
Sourcepub fn take_arena_boxes(
&mut self,
) -> (&Arena, Option<ArenaBox<'_, T>>, Option<ArenaBox<'_, [Option<MixedHandle>]>>)
pub fn take_arena_boxes( &mut self, ) -> (&Arena, Option<ArenaBox<'_, T>>, Option<ArenaBox<'_, [Option<MixedHandle>]>>)
Sourcepub fn into_raw(
self,
) -> (NonNull<fdf_arena_t>, Option<NonNull<T>>, Option<NonNull<[Option<MixedHandle>]>>)
pub fn into_raw( self, ) -> (NonNull<fdf_arena_t>, Option<NonNull<T>>, Option<NonNull<[Option<MixedHandle>]>>)
Source§impl<T> Message<MaybeUninit<T>>
impl<T> Message<MaybeUninit<T>>
Sourcepub unsafe fn assume_init(self) -> Message<T>
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>]>
impl<T> Message<[MaybeUninit<T>]>
Sourcepub unsafe fn assume_init(self) -> Message<[T]>
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>]>
impl Message<[MaybeUninit<u8>]>
Sourcepub unsafe fn cast_unchecked<T>(self) -> Message<T>
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