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 transform_attribute<'b, T: PrimitiveType, F: Fn(usize, T) -> T>(
        &'b mut self,
        attribute: &PointAttributeDefinition,
        func: F
    )
       where Self: Sized,
             'a: 'b { ... }
    fn view_mut<'b, T: PointType>(&'b mut self) -> PointViewMut<'a, 'b, Self, T>
       where Self: Sized,
             'a: 'b { ... }
    fn view_attribute_mut<'b, T: PrimitiveType>(
        &'b mut self,
        attribute: &PointAttributeDefinition
    ) -> AttributeViewMut<'a, 'b, Self, T>
       where Self: Sized,
             'a: 'b { ... }
    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 transform_attribute<'b, T: PrimitiveType, F: Fn(usize, T) -> T>( &'b mut self, attribute: &PointAttributeDefinition, func: F )
where Self: Sized, '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.

This function does not support attribute type conversion, so the type T must match the PointAttributeDataType of attribute!

The conversion function takes the current value of the attribute as a strongly typed T and returns the new value for the attribute. It also takes the index of the point within the buffer, so that func can access additional data.

Panics

If attribute is not part of the PointLayout of this buffer.
If T::data_type() does not equal attribute.datatype()

source

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

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

Panics

If T::point_layout() does not match self.point_layout()

source

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

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

Panics

If attribute is not part of the PointLayout of this buffer.
If T::data_type() does not match attribute.datatype()

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

Implementors§