pub struct MemoryLayout { /* private fields */ }Expand description
Memory layout representation: alignment and size aligned for this alignment
This API has been marked as unstable: it works as advertised, but it may be changed in a future release.
Implementations§
Source§impl MemoryLayout
impl MemoryLayout
Sourcepub fn new<T>(size: T, alignment: AllocAlignment) -> Result<Self, ZLayoutError>where
T: TryInto<NonZeroUsize>,
pub fn new<T>(size: T, alignment: AllocAlignment) -> Result<Self, ZLayoutError>where
T: TryInto<NonZeroUsize>,
Try to create a new memory layout.
This API has been marked as unstable: it works as advertised, but it may be changed in a future release.
§Errors
This function will return an error if zero size have passed or if the provided size is not the multiply of the alignment.
Sourcepub const fn for_type<T: Sized>() -> Self
pub const fn for_type<T: Sized>() -> Self
Creates a new MemoryLayout for type.
This API has been marked as unstable: it works as advertised, but it may be changed in a future release.
Sourcepub const fn for_value<T: Sized>(_: &T) -> Self
pub const fn for_value<T: Sized>(_: &T) -> Self
Creates a new MemoryLayout for value type.
This API has been marked as unstable: it works as advertised, but it may be changed in a future release.
pub fn size(&self) -> NonZeroUsize
pub fn alignment(&self) -> AllocAlignment
Sourcepub fn extend(
&self,
new_alignment: AllocAlignment,
) -> Result<MemoryLayout, ZLayoutError>
pub fn extend( &self, new_alignment: AllocAlignment, ) -> Result<MemoryLayout, ZLayoutError>
Realign the layout for new alignment. The alignment must be >= of the existing one.
This API has been marked as unstable: it works as advertised, but it may be changed in a future release.
# Examples
use zenoh_shm::api::provider::types::AllocAlignment;
use zenoh_shm::api::provider::memory_layout::MemoryLayout;
// 8 bytes with 4-byte alignment
let layout4b = MemoryLayout::new(8, AllocAlignment::new(2).unwrap()).unwrap();
// Try to realign with 2-byte alignment
let layout2b = layout4b.extend(AllocAlignment::new(1).unwrap());
assert!(layout2b.is_err()); // fails because new alignment must be >= old
// Try to realign with 8-byte alignment
let layout8b = layout4b.extend(AllocAlignment::new(3).unwrap());
assert!(layout8b.is_ok()); // okTrait Implementations§
Source§impl Clone for MemoryLayout
impl Clone for MemoryLayout
Source§fn clone(&self) -> MemoryLayout
fn clone(&self) -> MemoryLayout
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for MemoryLayout
impl Debug for MemoryLayout
Source§impl Display for MemoryLayout
impl Display for MemoryLayout
Source§impl From<&MemoryLayout> for MemoryLayout
impl From<&MemoryLayout> for MemoryLayout
Source§fn from(other: &MemoryLayout) -> Self
fn from(other: &MemoryLayout) -> Self
Converts to this type from the input type.
Source§impl PartialEq for MemoryLayout
impl PartialEq for MemoryLayout
Source§impl TryFrom<(NonZero<usize>, AllocAlignment)> for MemoryLayout
impl TryFrom<(NonZero<usize>, AllocAlignment)> for MemoryLayout
Source§type Error = ZLayoutError
type Error = ZLayoutError
The type returned in the event of a conversion error.
Source§fn try_from(value: (NonZeroUsize, AllocAlignment)) -> Result<Self, Self::Error>
fn try_from(value: (NonZeroUsize, AllocAlignment)) -> Result<Self, Self::Error>
Performs the conversion.
Source§impl TryFrom<(usize, AllocAlignment)> for MemoryLayout
impl TryFrom<(usize, AllocAlignment)> for MemoryLayout
Source§impl TryFrom<NonZero<usize>> for MemoryLayout
impl TryFrom<NonZero<usize>> for MemoryLayout
Source§type Error = ZLayoutError
type Error = ZLayoutError
The type returned in the event of a conversion error.
Source§impl TryFrom<usize> for MemoryLayout
impl TryFrom<usize> for MemoryLayout
impl Copy for MemoryLayout
impl Eq for MemoryLayout
impl StructuralPartialEq for MemoryLayout
Auto Trait Implementations§
impl Freeze for MemoryLayout
impl RefUnwindSafe for MemoryLayout
impl Send for MemoryLayout
impl Sync for MemoryLayout
impl Unpin for MemoryLayout
impl UnwindSafe for MemoryLayout
Blanket Implementations§
Source§impl<Source> AccessAs for Source
impl<Source> AccessAs for Source
Source§impl<T> AllocLayout for T
impl<T> AllocLayout for T
Source§fn memory_layout(self) -> Result<MemoryLayout, ZLayoutError>
fn memory_layout(self) -> Result<MemoryLayout, ZLayoutError>
Returns the memory layouts of the allocation.
Source§unsafe fn wrap_buffer(buffer: ZShmMut) -> <T as AllocLayout>::Buffer
unsafe fn wrap_buffer(buffer: ZShmMut) -> <T as AllocLayout>::Buffer
Wraps the raw allocated buffer. Read more
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more