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
andset_attribute
- Shuffling data through
swap
- Mutable views to points and attributes through
view_mut
andview_attribute_mut
Required Methods§
sourceunsafe fn set_point(&mut self, index: usize, point_data: &[u8])
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()
sourceunsafe fn set_point_range(
&mut self,
point_range: Range<usize>,
point_data: &[u8],
)
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()
sourceunsafe fn set_attribute(
&mut self,
attribute: &PointAttributeDefinition,
index: usize,
attribute_data: &[u8],
)
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
sourceunsafe fn set_attribute_range(
&mut self,
attribute: &PointAttributeDefinition,
point_range: Range<usize>,
attribute_data: &[u8],
)
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()
Provided Methods§
sourcefn as_interleaved_mut(&mut self) -> Option<&mut dyn InterleavedBufferMut<'a>>
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
sourcefn as_columnar_mut(&mut self) -> Option<&mut dyn ColumnarBufferMut<'a>>
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
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,
fn view<'b, T: PointType>(&'b self) -> PointView<'a, 'b, Self, T>where
'a: 'b,
source§fn view_attribute<'b, T: PrimitiveType>(
&'b self,
attribute: &PointAttributeDefinition,
) -> AttributeView<'a, 'b, Self, T>where
'a: 'b,
fn view_attribute<'b, T: PrimitiveType>(
&'b self,
attribute: &PointAttributeDefinition,
) -> AttributeView<'a, 'b, Self, T>where
'a: 'b,
attribute
of all points in this buffer Read moresource§fn view_attribute_with_conversion<'b, T: PrimitiveType>(
&'b self,
attribute: &PointAttributeDefinition,
) -> Result<AttributeViewConverting<'a, 'b, Self, T>>where
'a: 'b,
fn view_attribute_with_conversion<'b, T: PrimitiveType>(
&'b self,
attribute: &PointAttributeDefinition,
) -> Result<AttributeViewConverting<'a, 'b, Self, T>>where
'a: 'b,
view_attribute
, but allows T::data_type()
to be different from the data type ofthe
attribute
within this buffer. Read moresource§impl<'a> BorrowedMutBufferExt<'a> for dyn BorrowedMutBuffer<'a> + 'a
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,
fn view_mut<'b, T: PointType>(&'b mut self) -> PointViewMut<'a, 'b, Self, T>where
'a: 'b,
source§fn view_attribute_mut<'b, T: PrimitiveType>(
&'b mut self,
attribute: &PointAttributeDefinition,
) -> AttributeViewMut<'a, 'b, Self, T>where
'a: 'b,
fn view_attribute_mut<'b, T: PrimitiveType>(
&'b mut self,
attribute: &PointAttributeDefinition,
) -> AttributeViewMut<'a, 'b, Self, T>where
'a: 'b,
attribute
of all points in this buffer. This view allows mutating
the attribute data! Read moresource§fn transform_attribute<'b, T: PrimitiveType, F: Fn(usize, T) -> T>(
&'b mut self,
attribute: &PointAttributeDefinition,
func: F,
)where
'a: 'b,
fn transform_attribute<'b, T: PrimitiveType, F: Fn(usize, T) -> T>(
&'b mut self,
attribute: &PointAttributeDefinition,
func: F,
)where
'a: 'b,
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