Trait pasture_core::containers::BorrowedMutBuffer

source ·
pub trait BorrowedMutBuffer<'a>: BorrowedBuffer<'a> {
    // Required methods
    unsafe fn set_point(&mut self, index: usize, point_data: &[u8]);
    unsafe fn set_point_range(
        &mut self,
        point_range: Range<usize>,
        point_data: &[u8],
    );
    unsafe fn set_attribute(
        &mut self,
        attribute: &PointAttributeDefinition,
        index: usize,
        attribute_data: &[u8],
    );
    unsafe fn set_attribute_range(
        &mut self,
        attribute: &PointAttributeDefinition,
        point_range: Range<usize>,
        attribute_data: &[u8],
    );
    fn swap(&mut self, from_index: usize, to_index: usize);

    // Provided methods
    fn as_interleaved_mut(
        &mut self,
    ) -> Option<&mut dyn InterleavedBufferMut<'a>> { ... }
    fn as_columnar_mut(&mut self) -> Option<&mut dyn ColumnarBufferMut<'a>> { ... }
}
Expand description

Trait for a point buffer that mutably borrows its memory. Compared to BorrowedBuffer, buffers that implement this trait support the following additional capabilities:

  • Manipulating point and attribute data in-place through set_point and set_attribute
  • Shuffling data through swap
  • Mutable views to points and attributes through view_mut and view_attribute_mut

Required Methods§

source

unsafe fn set_point(&mut self, index: usize, point_data: &[u8])

Sets the data for the point at the given index

§Safety

Requires that point_data contains memory for a single point with the same PointLayout as self.point_layout(). This property is not enforced at runtime, so this function is very unsafe!

§Panics

May panic if index is out of bounds.
May panic if point_data.len() does not equal self.point_layout().size_of_point_record()

source

unsafe fn set_point_range( &mut self, point_range: Range<usize>, point_data: &[u8], )

Sets the data for the given range of points. This function will generally be more efficient than calling [set_point] multiple times, as [set_point] performs size and index checks on every call, whereas this function can perform them only once. Assumes that the point_data is tightly packed, i.e. stored in an interleaved format with point alignment of 1.

§Safety

point_data must contain correctly initialized data for point_range.len() points in interleaved layout. The data must be tightly packed (i.e. no padding bytes between adjacent points).

§Panics

May panic if point_range is out of bounds.
May panic if point_data.len() does not equal point_range.len() * self.point_layout().size_of_point_record()

source

unsafe fn set_attribute( &mut self, attribute: &PointAttributeDefinition, index: usize, attribute_data: &[u8], )

Sets the data for the given attribute of the point at index

§Safety

Requires that attribute_data contains memory for a single value of the data type of attribute. This property is not enforced at runtime, so this function is very unsafe!

§Panics

May panic if attribute is not part of the PointLayout of this buffer.
May panic if index is out of bounds.
May panic if attribute_data.len() does not match the size of the data type of attribute

source

unsafe fn set_attribute_range( &mut self, attribute: &PointAttributeDefinition, point_range: Range<usize>, attribute_data: &[u8], )

Sets the data for the given attribute for all points in point_range. This function will generally be more efficient than calling [set_attribute] multiple times, as [set_attribute] has to perform type and bounds checks on each call.

§Safety

Requires that attribute_data contains data for point_range.len() attribute values. The data must be tightly packed, i.e. there must be no padding bytes between adjacent values.

§Panics

May panic if attribute is not part of the PointLayout of this buffer.
May panic if point_range is out of bounds.
May panic if attribute_data.len() does not equal point_range.len() * attribute.size()

source

fn swap(&mut self, from_index: usize, to_index: usize)

Swaps the two points at from_index and to_index. Implementations should allow the case where from_index == to_index

§Panics

May panic if any of from_index or to_index is out of bounds

Provided Methods§

source

fn as_interleaved_mut(&mut self) -> Option<&mut dyn InterleavedBufferMut<'a>>

Try to get a mutable reference to self as an InterleavedBufferMut. Returns None if self does not implement InterleavedBufferMut

source

fn as_columnar_mut(&mut self) -> Option<&mut dyn ColumnarBufferMut<'a>>

Try to get a mutable reference to self as a ColumnarBufferMut. Returns None if self does not implement ColumnarBufferMut

Trait Implementations§

source§

impl<'a> BorrowedBufferExt<'a> for dyn BorrowedMutBuffer<'a> + 'a

source§

fn view<'b, T: PointType>(&'b self) -> PointView<'a, 'b, Self, T>
where 'a: 'b,

Get a strongly typed view of the point data of this buffer Read more
source§

fn view_attribute<'b, T: PrimitiveType>( &'b self, attribute: &PointAttributeDefinition, ) -> AttributeView<'a, 'b, Self, T>
where 'a: 'b,

Gets a strongly typed view of the attribute of all points in this buffer Read more
source§

fn view_attribute_with_conversion<'b, T: PrimitiveType>( &'b self, attribute: &PointAttributeDefinition, ) -> Result<AttributeViewConverting<'a, 'b, Self, T>>
where 'a: 'b,

Like view_attribute, but allows T::data_type() to be different from the data type of
the attribute within this buffer. Read more
source§

impl<'a> BorrowedMutBufferExt<'a> for dyn BorrowedMutBuffer<'a> + 'a

source§

fn view_mut<'b, T: PointType>(&'b mut self) -> PointViewMut<'a, 'b, Self, T>
where 'a: 'b,

Get a strongly typed view of the point data of this buffer. This view allows mutating the point data! Read more
source§

fn view_attribute_mut<'b, T: PrimitiveType>( &'b mut self, attribute: &PointAttributeDefinition, ) -> AttributeViewMut<'a, 'b, Self, T>
where 'a: 'b,

Get a strongly typed view of the attribute of all points in this buffer. This view allows mutating the attribute data! Read more
source§

fn transform_attribute<'b, T: PrimitiveType, F: Fn(usize, T) -> T>( &'b mut self, attribute: &PointAttributeDefinition, func: F, )
where 'a: 'b,

Apply a transformation function to the given attribute of all points within this buffer. This function is helpful if you want to modify a single attribute of a buffer in-place and works for buffers of all memory layouts. For columnar buffers, prefer using get_attribute_range_mut to modify attribute data in-place. Read more
source§

impl<'a> SliceBuffer<'a> for dyn BorrowedMutBuffer<'a> + 'a

§

type SliceType = BufferSlice<'a, dyn BorrowedMutBuffer<'a> + 'a>

The slice type
source§

fn slice(&'a self, range: Range<usize>) -> Self::SliceType

Take a immutable slice to this buffer using the given range of points Read more
source§

impl<'a> SliceBufferMut<'a> for dyn BorrowedMutBuffer<'a> + 'a

§

type SliceTypeMut = BufferSliceMut<'a, dyn BorrowedMutBuffer<'a> + 'a>

source§

fn slice_mut(&'a mut self, range: Range<usize>) -> Self::SliceTypeMut

Take a mutable slice to this buffer using the given range of points Read more

Implementors§