Skip to main content

Relocate

Trait Relocate 

Source
pub trait Relocate: Layout {
    // Required methods
    fn byte_offset(&self) -> usize;
    fn relocate(&mut self, offset: AlignedOffset);

    // Provided methods
    fn relocate_to_byte(&mut self, offset: usize) -> bool { ... }
    fn byte_range(&self) -> Range<usize> { ... }
    fn texel_range(&self) -> TexelRange<Self::Sample>
       where Self: SliceLayout + Sized { ... }
}
Expand description

A layout that supports being moved in memory.

Such a layout only occupies a smaller but contiguous range of its full buffer length. One can query that offset and modify it. Note that a relocatable layout should still report its Layout::byte_len as the past-the-end of its last relevant byte.

Required Methods§

Source

fn byte_offset(&self) -> usize

The offset of the first relevant byte of this layout.

This should be smaller or equal to the length.

Source

fn relocate(&mut self, offset: AlignedOffset)

Move the layout to another aligned offset.

The length of the layout should implicitly be modified by this operation, that is the range between the start offset and its apparent length should remain the same.

Moving to an aligned offset must work.

§Panics

Implementations are encouraged to panic if the newly chosen offset would make the total length overflow isize::MAX, i.e. possible allocation size.

Provided Methods§

Source

fn relocate_to_byte(&mut self, offset: usize) -> bool

Attempt to relocate the offset to another start offset, in bytes.

This method should return false if the new offset is not suitable for the layout. The default implementation requires an aligned offset. Implementations may work for additional offsets.

Source

fn byte_range(&self) -> Range<usize>

Retrieve the contiguous byte range occupied by this layout.

Source

fn texel_range(&self) -> TexelRange<Self::Sample>
where Self: SliceLayout + Sized,

Get an index addressing all samples covered by the range of this relocated layout.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T: Layout> Relocate for Relocated<T>

Source§

impl<const N: usize> Relocate for PlaneBytes<N>