[−][src]Struct bit_mask_ring_buf::BMRingBuf
A fast ring buffer implementation with cheap and safe indexing. It works by bit-masking
an integer index to get the corresponding index in an array/vec whose length
is a power of 2. This is best used when indexing the buffer with an isize
value.
Copies/reads with slices are implemented with memcpy.
Implementations
impl BMRingBuf<f32>
[src]
pub fn lin_interp_f32(&self, index: f32) -> f32
[src]
Gets the linearly interpolated value between the two values
at index.floor()
and index.floor() + 1
, where index
is an f32
.
Example
use bit_mask_ring_buf::BMRingBuf; let mut rb = BMRingBuf::<f32>::from_len(4); rb[0] = 0.0; rb[1] = 2.0; rb[2] = 4.0; rb[3] = 6.0; assert!((rb.lin_interp_f32(1.0) - 2.0).abs() <= f32::EPSILON); assert!((rb.lin_interp_f32(1.25) - 2.5).abs() <= f32::EPSILON); assert!((rb.lin_interp_f32(3.75) - 1.5).abs() <= f32::EPSILON);
pub fn lin_interp_f64(&self, index: f64) -> f32
[src]
Gets the linearly interpolated value between the two values
at index.floor()
and index.floor() + 1
, where index
is an f64
.
Example
use bit_mask_ring_buf::BMRingBuf; let mut rb = BMRingBuf::<f32>::from_len(4); rb[0] = 0.0; rb[1] = 2.0; rb[2] = 4.0; rb[3] = 6.0; assert!((rb.lin_interp_f64(1.0f64) - 2.0).abs() <= f32::EPSILON); assert!((rb.lin_interp_f64(1.25f64) - 2.5).abs() <= f32::EPSILON); assert!((rb.lin_interp_f64(3.75f64) - 1.5).abs() <= f32::EPSILON);
impl BMRingBuf<f64>
[src]
pub fn lin_interp_f32(&self, index: f32) -> f64
[src]
Gets the linearly interpolated value between the two values
at index.floor()
and index.floor() + 1
, where index
is an f32
.
Example
use bit_mask_ring_buf::BMRingBuf; let mut rb = BMRingBuf::<f64>::from_len(4); rb[0] = 0.0; rb[1] = 2.0; rb[2] = 4.0; rb[3] = 6.0; assert!((rb.lin_interp_f32(1.0f32) - 2.0).abs() <= f64::EPSILON); assert!((rb.lin_interp_f32(1.25f32) - 2.5).abs() <= f64::EPSILON); assert!((rb.lin_interp_f32(3.75f32) - 1.5).abs() <= f64::EPSILON);
pub fn lin_interp_f64(&self, index: f64) -> f64
[src]
Gets the linearly interpolated value between the two values
at index.floor()
and index.floor() + 1
, where index
is an f64
.
Example
use bit_mask_ring_buf::BMRingBuf; let mut rb = BMRingBuf::<f64>::from_len(4); rb[0] = 0.0; rb[1] = 2.0; rb[2] = 4.0; rb[3] = 6.0; assert!((rb.lin_interp_f64(1.0) - 2.0).abs() <= f64::EPSILON); assert!((rb.lin_interp_f64(1.25) - 2.5).abs() <= f64::EPSILON); assert!((rb.lin_interp_f64(3.75) - 1.5).abs() <= f64::EPSILON);
impl<T: Copy + Clone + Default> BMRingBuf<T>
[src]
pub fn from_len(len: usize) -> Self
[src]
Creates a new BMRingBuf
with a length that is at least the given
length. The buffer will be initialized with the default value.
len
- The length of the ring buffer. The actual length will be set to the next highest power of 2 iflen
is not already a power of 2. The length will be set to 2 iflen < 2
.
Example
use bit_mask_ring_buf::BMRingBuf; let rb = BMRingBuf::<u32>::from_len(3); assert_eq!(rb.len(), 4); assert_eq!(rb[0], 0); assert_eq!(rb[1], 0); assert_eq!(rb[2], 0); assert_eq!(rb[3], 0);
Panics
- This will panic if this tries to allocate more than
isize::MAX
bytes - This will panic if
len > (std::usize::MAX/2)+1
pub fn from_len_with_capacity(len: usize, capacity: usize) -> Self
[src]
Creates a new BMRingBuf
with a length that is at least the given
length, while reserving extra capacity for future changes to len
.
All data from [0..len)
will be initialized with the default value.
len
- The length of the ring buffer. The actual length will be set to the next highest power of 2 iflen
is not already a power of 2. The length will be set to 2 iflen < 2
.capacity
- The allocated capacity of the ring buffer. The actual capacity will be set to the next highest power of 2 ifcapacity
is not already a power of 2. The capacity will be set to 2 ifcapacity < 2
. If this is less thanlen
, then it will be ignored.
Example
use bit_mask_ring_buf::BMRingBuf; let rb = BMRingBuf::<u32>::from_len_with_capacity(3, 15); assert_eq!(rb.len(), 4); assert!(rb.capacity() >= 16); assert_eq!(rb[0], 0); assert_eq!(rb[1], 0); assert_eq!(rb[2], 0); assert_eq!(rb[3], 0);
Panics
- This will panic if this tries to allocate more than
isize::MAX
bytes - This will panic if
len > (std::usize::MAX/2)+1
- This will panic if
capacity > (std::usize::MAX/2)+1
pub unsafe fn from_len_uninit(len: usize) -> Self
[src]
Creates a new BMRingBuf
with a length that is at least the given
length. The data in the buffer will not be initialized.
len
- The length of the ring buffer. The actual length will be set to the next highest power of 2 iflen
is not already a power of 2. The length will be set to 2 iflen < 2
.
Safety
- Undefined behavior may occur if uninitialized data is read from. By using this you assume the responsibility of making sure any data is initialized before it is read.
Example
use bit_mask_ring_buf::BMRingBuf; unsafe { let rb = BMRingBuf::<u32>::from_len_uninit(3); assert_eq!(rb.len(), 4); }
Panics
- This will panic if this tries to allocate more than
isize::MAX
bytes - This will panic if
len > (std::usize::MAX/2)+1
pub unsafe fn from_len_with_capacity_uninit(len: usize, capacity: usize) -> Self
[src]
Creates a new BMRingBuf
with a length that is at least the given
length, while reserving extra capacity for future changes to len
.
The data in the buffer will not be initialized.
len
- The length of the ring buffer. The actual length will be set to the next highest power of 2 iflen
is not already a power of 2. The length will be set to 2 iflen < 2
.capacity
- The allocated capacity of the ring buffer. The actual capacity will be set to the next highest power of 2 ifcapacity
is not already a power of 2. The capacity will be set to 2 ifcapacity < 2
. If this is less thanlen
, then it will be ignored.
Safety
- Undefined behavior may occur if uninitialized data is read from. By using this you assume the responsibility of making sure any data is initialized before it is read.
Example
use bit_mask_ring_buf::BMRingBuf; unsafe { let rb = BMRingBuf::<u32>::from_len_with_capacity_uninit(3, 15); assert_eq!(rb.len(), 4); assert!(rb.capacity() >= 16); }
Panics
- This will panic if this tries to allocate more than
isize::MAX
bytes - This will panic if
len > (std::usize::MAX/2)+1
pub fn clear_set_len(&mut self, len: usize)
[src]
Sets the length of the ring buffer while clearing all values to the default value.
The actual length will be set to the next highest power of 2 if len
is not already a power of 2.
The length will be set to 2 if len < 2
.
Example
use bit_mask_ring_buf::BMRingBuf; let mut rb = BMRingBuf::<u32>::from_len(2); rb[0] = 1; rb[1] = 2; rb.clear_set_len(3); assert_eq!(rb.len(), 4); assert_eq!(rb[0], 0); assert_eq!(rb[1], 0); assert_eq!(rb[2], 0); assert_eq!(rb[3], 0);
Panics
- This will panic if this tries to allocate more than
isize::MAX
bytes - This will panic if
len > (std::usize::MAX/2)+1
pub fn set_len(&mut self, len: usize)
[src]
Sets the length of the ring buffer.
- If the resulting length is less than the current length, then the data will be truncated.
- If the resulting length is larger than the current length, then all newly allocated elements appended to the end will be initialized with the default value.
The actual length will be set to the next highest power of 2 if len
is not already a power of 2.
The length will be set to 2 if len < 2
.
Example
use bit_mask_ring_buf::BMRingBuf; let mut rb = BMRingBuf::<u32>::from_len(2); rb[0] = 1; rb[1] = 2; rb.set_len(3); assert_eq!(rb.len(), 4); assert_eq!(rb[0], 1); assert_eq!(rb[1], 2); assert_eq!(rb[2], 0); assert_eq!(rb[3], 0);
Panics
- This will panic if this tries to allocate more than
isize::MAX
bytes - This will panic if
len > (std::usize::MAX/2)+1
pub unsafe fn set_len_uninit(&mut self, len: usize)
[src]
Sets the length of the ring buffer without initializing any newly allocated data.
- If the resulting length is less than the current length, then the data will be truncated.
- If the resulting length is larger than the current length, then all newly allocated elements appended to the end will be unitialized.
Safety
- Undefined behavior may occur if uninitialized data is read from. By using this you assume the responsibility of making sure any data is initialized before it is read.
Example
use bit_mask_ring_buf::BMRingBuf; let mut rb = BMRingBuf::<u32>::from_len(2); rb[0] = 1; rb[1] = 2; unsafe { rb.set_len_uninit(3); assert_eq!(rb.len(), 4); assert_eq!(rb[0], 1); assert_eq!(rb[1], 2); }
Panics
- This will panic if this tries to allocate more than
isize::MAX
bytes - This will panic if
len > (std::usize::MAX/2)+1
pub fn clear(&mut self)
[src]
Clears all values in the ring buffer to the default value.
Example
use bit_mask_ring_buf::BMRingBuf; let mut rb = BMRingBuf::<u32>::from_len(2); rb[0] = 1; rb[1] = 2; rb.clear(); assert_eq!(rb[0], 0); assert_eq!(rb[1], 0);
pub fn reserve(&mut self, additional: usize)
[src]
Reserves capacity for at least additional
more elements to be inserted
in the internal Vec
. This is equivalant to Vec::reserve()
.
The actual capacity will be set to the next highest power of 2 if the resulting capacity is not already a power of 2. The capacity will be set to 2 if the resulting capacity is less than 2.
Note that the allocator may give the collection more space than it requests. Therefore, capacity can not be relied upon to be precisely minimal.
Example
use bit_mask_ring_buf::BMRingBuf; let mut rb = BMRingBuf::<u32>::from_len(2); rb.reserve(8); // next_pow_of_2(2 + 8) == 16 assert!(rb.capacity() >= 16);
Panics
- This will panic if the new capacity overflows
usize
. - This will panic if this tries to allocate more than
isize::MAX
bytes - This will panic if the resulting length is greater than
(std::usize::MAX/2)+1
pub fn shrink_to_fit(&mut self)
[src]
Shrinks the capacity of the internal Vec
as much as possible. This is equivalant to
Vec::shrink_to_fit
.
It will drop down as close as possible to the length but the allocator may still inform the vector that there is space for a few more elements.
Example
use bit_mask_ring_buf::BMRingBuf; let mut rb = BMRingBuf::<u32>::from_len(2); rb.reserve(8); // next_pow_of_2(2 + 8) == 16 assert!(rb.capacity() >= 16); rb.shrink_to_fit(); assert!(rb.capacity() >= 2);
pub fn as_slices(&self, start: isize) -> (&[T], &[T])
[src]
Returns two slices that contain all the data in the ring buffer
starting at the index start
.
Returns
- The first slice is the starting chunk of data. This will never be empty.
- The second slice is the second contiguous chunk of data. This may or may not be empty depending if the buffer needed to wrap around to the beginning of its internal memory layout.
Performance
Prefer to use this to manipulate data in bulk over indexing one element at a time.
Example
use bit_mask_ring_buf::BMRingBuf; let mut rb = BMRingBuf::<u32>::from_len(4); rb[0] = 1; rb[1] = 2; rb[2] = 3; rb[3] = 4; let (s1, s2) = rb.as_slices(-4); assert_eq!(s1, &[1, 2, 3, 4]); assert_eq!(s2, &[]); let (s1, s2) = rb.as_slices(3); assert_eq!(s1, &[4]); assert_eq!(s2, &[1, 2, 3]);
pub fn as_slices_len(&self, start: isize, len: usize) -> (&[T], &[T])
[src]
Returns two slices of data in the ring buffer
starting at the index start
and with length len
.
start
- The starting indexlen
- The length of data to read. Iflen
is greater than the length of the ring buffer, then the buffer's length will be used instead.
Returns
- The first slice is the starting chunk of data.
- The second slice is the second contiguous chunk of data. This may or may not be empty depending if the buffer needed to wrap around to the beginning of its internal memory layout.
Performance
Prefer to use this to manipulate data in bulk over indexing one element at a time.
Example
use bit_mask_ring_buf::BMRingBuf; let mut rb = BMRingBuf::<u32>::from_len(4); rb[0] = 1; rb[1] = 2; rb[2] = 3; rb[3] = 4; let (s1, s2) = rb.as_slices_len(-4, 3); assert_eq!(s1, &[1, 2, 3]); assert_eq!(s2, &[]); let (s1, s2) = rb.as_slices_len(3, 5); assert_eq!(s1, &[4]); assert_eq!(s2, &[1, 2, 3]);
pub fn as_slices_latest(&self, start: isize, len: usize) -> (&[T], &[T])
[src]
Returns two slices of data in the ring buffer
starting at the index start
and with length len
. If len
is greater
than the length of the ring buffer, then the buffer's length will be used
instead, while still preserving the position of the last element.
start
- The starting indexlen
- The length of data to read. Iflen
is greater than the length of the ring buffer, then the buffer's length will be used instead, while still preserving the position of the last element.
Returns
- The first slice is the starting chunk of data.
- The second slice is the second contiguous chunk of data. This may or may not be empty depending if the buffer needed to wrap around to the beginning of its internal memory layout.
Performance
Prefer to use this to manipulate data in bulk over indexing one element at a time.
Example
use bit_mask_ring_buf::BMRingBuf; let mut rb = BMRingBuf::<u32>::from_len(4); rb[0] = 1; rb[1] = 2; rb[2] = 3; rb[3] = 4; let (s1, s2) = rb.as_slices_latest(-4, 3); assert_eq!(s1, &[1, 2, 3]); assert_eq!(s2, &[]); let (s1, s2) = rb.as_slices_latest(0, 5); assert_eq!(s1, &[2, 3, 4]); assert_eq!(s2, &[1]);
pub fn as_mut_slices(&mut self, start: isize) -> (&mut [T], &mut [T])
[src]
Returns two mutable slices that contain all the data in the ring buffer
starting at the index start
.
Returns
- The first slice is the starting chunk of data. This will never be empty.
- The second slice is the second contiguous chunk of data. This may or may not be empty depending if the buffer needed to wrap around to the beginning of its internal memory layout.
Performance
Prefer to use this to manipulate data in bulk over indexing one element at a time.
Example
use bit_mask_ring_buf::BMRingBuf; let mut rb = BMRingBuf::<u32>::from_len(4); rb[0] = 1; rb[1] = 2; rb[2] = 3; rb[3] = 4; let (s1, s2) = rb.as_mut_slices(-4); assert_eq!(s1, &mut [1, 2, 3, 4]); assert_eq!(s2, &mut []); let (s1, s2) = rb.as_mut_slices(3); assert_eq!(s1, &mut [4]); assert_eq!(s2, &mut [1, 2, 3]);
pub fn as_mut_slices_len(
&mut self,
start: isize,
len: usize
) -> (&mut [T], &mut [T])
[src]
&mut self,
start: isize,
len: usize
) -> (&mut [T], &mut [T])
Returns two mutable slices of data in the ring buffer
starting at the index start
and with length len
.
start
- The starting indexlen
- The length of data to read. Iflen
is greater than the length of the ring buffer, then the buffer's length will be used instead.
Returns
- The first slice is the starting chunk of data.
- The second slice is the second contiguous chunk of data. This may or may not be empty depending if the buffer needed to wrap around to the beginning of its internal memory layout.
Performance
Prefer to use this to manipulate data in bulk over indexing one element at a time.
Example
use bit_mask_ring_buf::BMRingBuf; let mut rb = BMRingBuf::<u32>::from_len(4); rb[0] = 1; rb[1] = 2; rb[2] = 3; rb[3] = 4; let (s1, s2) = rb.as_mut_slices_len(-4, 3); assert_eq!(s1, &mut [1, 2, 3]); assert_eq!(s2, &mut []); let (s1, s2) = rb.as_mut_slices_len(3, 5); assert_eq!(s1, &mut [4]); assert_eq!(s2, &mut [1, 2, 3]);
pub fn as_mut_slices_latest(
&mut self,
start: isize,
len: usize
) -> (&mut [T], &mut [T])
[src]
&mut self,
start: isize,
len: usize
) -> (&mut [T], &mut [T])
Returns two mutable slices of data in the ring buffer
starting at the index start
and with length len
. If len
is greater
than the length of the ring buffer, then the buffer's length will be used
instead, while still preserving the position of the last element.
start
- The starting indexlen
- The length of data to read. Iflen
is greater than the length of the ring buffer, then the buffer's length will be used instead, while still preserving the position of the last element.
Returns
- The first slice is the starting chunk of data.
- The second slice is the second contiguous chunk of data. This may or may not be empty depending if the buffer needed to wrap around to the beginning of its internal memory layout.
Performance
Prefer to use this to manipulate data in bulk over indexing one element at a time.
Example
use bit_mask_ring_buf::BMRingBuf; let mut rb = BMRingBuf::<u32>::from_len(4); rb[0] = 1; rb[1] = 2; rb[2] = 3; rb[3] = 4; let (s1, s2) = rb.as_mut_slices_latest(-4, 3); assert_eq!(s1, &mut [1, 2, 3]); assert_eq!(s2, &mut []); let (s1, s2) = rb.as_mut_slices_latest(0, 5); assert_eq!(s1, &mut [2, 3, 4]); assert_eq!(s2, &mut [1]);
pub fn read_into(&self, slice: &mut [T], start: isize)
[src]
Copies the data from the ring buffer starting from the index start
into the given slice. If the length of slice
is larger than the
length of the ring buffer, then the data will be reapeated until
the given slice is filled.
slice
- This slice to copy the data into.start
- The index of the ring buffer to start copying from.
Performance
Prefer to use this to manipulate data in bulk over indexing one element at a time.
Example
use bit_mask_ring_buf::BMRingBuf; let mut rb = BMRingBuf::<u32>::from_len(4); rb[0] = 1; rb[1] = 2; rb[2] = 3; rb[3] = 4; let mut read_buf = [0u32; 3]; rb.read_into(&mut read_buf[..], -3); assert_eq!(read_buf, [2, 3, 4]); let mut read_buf = [0u32; 9]; rb.read_into(&mut read_buf[..], 2); assert_eq!(read_buf, [3, 4, 1, 2, 3, 4, 1, 2, 3]);
pub fn write_latest(&mut self, slice: &[T], start: isize)
[src]
Copies data from the given slice into the ring buffer starting from
the index start
.
Earlier data will not be copied if it will be overwritten by newer data, avoiding unecessary memcpy's. The correct placement of the newer data will still be preserved.
slice
- This slice to copy data from.start
- The index of the ring buffer to start copying from.
Performance
Prefer to use this to manipulate data in bulk over indexing one element at a time.
Example
use bit_mask_ring_buf::BMRingBuf; let mut rb = BMRingBuf::<u32>::from_len(4); let input = [1u32, 2, 3]; rb.write_latest(&input[..], -3); assert_eq!(rb[0], 0); assert_eq!(rb[1], 1); assert_eq!(rb[2], 2); assert_eq!(rb[3], 3); let input = [1u32, 2, 3, 4, 5, 6, 7, 8, 9]; rb.write_latest(&input[..], 2); assert_eq!(rb[0], 7); assert_eq!(rb[1], 8); assert_eq!(rb[2], 9); assert_eq!(rb[3], 6);
pub fn write_latest_2(&mut self, first: &[T], second: &[T], start: isize)
[src]
Copies data from two given slices into the ring buffer starting from
the index start
. The first
slice will be copied first then second
will be copied next.
Earlier data will not be copied if it will be overwritten by newer data, avoiding unecessary memcpy's. The correct placement of the newer data will still be preserved.
first
- This first slice to copy data from.second
- This second slice to copy data from.start
- The index of the ring buffer to start copying from.
Performance
Prefer to use this to manipulate data in bulk over indexing one element at a time.
Example
use bit_mask_ring_buf::BMRingBuf; let mut input_rb = BMRingBuf::<u32>::from_len(4); input_rb[0] = 1; input_rb[1] = 2; input_rb[2] = 3; input_rb[3] = 4; let mut output_rb = BMRingBuf::<u32>::from_len(4); // s1 == &[1, 2], s2 == &[] let (s1, s2) = input_rb.as_slices_len(0, 2); output_rb.write_latest_2(s1, s2, -3); assert_eq!(output_rb[0], 0); assert_eq!(output_rb[1], 1); assert_eq!(output_rb[2], 2); assert_eq!(output_rb[3], 0); let mut output_rb = BMRingBuf::<u32>::from_len(2); // s1 == &[4], s2 == &[1, 2, 3] let (s1, s2) = input_rb.as_slices_len(3, 4); // rb[1] = 4 -> rb[0] = 1 -> rb[1] = 2 -> rb[0] = 3 output_rb.write_latest_2(s1, s2, 1); assert_eq!(output_rb[0], 3); assert_eq!(output_rb[1], 2);
pub fn len(&self) -> usize
[src]
Returns the length of the ring buffer.
Example
use bit_mask_ring_buf::BMRingBuf; let rb = BMRingBuf::<u32>::from_len(4); assert_eq!(rb.len(), 4);
pub fn capacity(&self) -> usize
[src]
Returns the allocated capacity of the ring buffer.
Please note this is not the same as the length of the buffer. For that use BMRingBuf::len().
Example
use bit_mask_ring_buf::BMRingBuf; let rb = BMRingBuf::<u32>::from_len(4); assert!(rb.capacity() >= 4);
pub fn constrain(&self, i: isize) -> isize
[src]
Returns the actual index of the ring buffer from the given
i
index. This is cheap due to the ring buffer's bit-masking
algorithm. This is useful to keep indexes from growing indefinitely.
Example
use bit_mask_ring_buf::BMRingBuf; let rb = BMRingBuf::<u32>::from_len(4); assert_eq!(rb.constrain(2), 2); assert_eq!(rb.constrain(4), 0); assert_eq!(rb.constrain(-3), 1); assert_eq!(rb.constrain(7), 3);
pub fn raw_data(&self) -> &[T]
[src]
Returns all the data in the buffer. The starting index will
always be 0
.
Example
use bit_mask_ring_buf::BMRingBuf; let mut rb = BMRingBuf::<u32>::from_len(4); rb[0] = 1; rb[1] = 2; rb[2] = 3; rb[3] = 4; let raw_data = rb.raw_data(); assert_eq!(raw_data, &[1u32, 2, 3, 4]);
pub fn raw_data_mut(&mut self) -> &mut [T]
[src]
Returns all the data in the buffer as mutable. The starting
index will always be 0
.
Example
use bit_mask_ring_buf::BMRingBuf; let mut rb = BMRingBuf::<u32>::from_len(4); rb[0] = 1; rb[1] = 2; rb[2] = 3; rb[3] = 4; let raw_data = rb.raw_data_mut(); assert_eq!(raw_data, &mut [1u32, 2, 3, 4]);
pub fn raw_at(&self, i: usize) -> &T
[src]
Returns the element at the index of type usize
.
Please note this does NOT wrap around. This is equivalent to
indexing a normal Vec
.
Example
use bit_mask_ring_buf::BMRingBuf; let mut rb = BMRingBuf::<u32>::from_len(4); rb[0] = 1; rb[3] = 4; assert_eq!(*rb.raw_at(0), 1); assert_eq!(*rb.raw_at(3), 4); // These will panic! // assert_eq!(*rb.raw_at(-3), 2); // assert_eq!(*rb.raw_at(4), 1);
Panics
- This will panic if
i
is out of bounds of the internalVec
.
pub fn raw_at_mut(&mut self, i: usize) -> &mut T
[src]
Returns the element at the index of type usize
as mutable.
Please note this does NOT wrap around. This is equivalent to
indexing a normal Vec
.
Example
use bit_mask_ring_buf::BMRingBuf; let mut rb = BMRingBuf::<u32>::from_len(4); *rb.raw_at_mut(0) = 1; *rb.raw_at_mut(3) = 4; assert_eq!(rb[0], 1); assert_eq!(rb[3], 4); // These will panic! // *rb.raw_at_mut(-3) = 2; // *rb.raw_at_mut(4) = 1;
Panics
- This will panic if
i
is out of bounds of the internalVec
.
pub fn at(&self, i: &mut isize) -> &T
[src]
Returns the element at the index of type usize
while also
constraining the index i
. This is slightly more efficient
than calling both methods individually.
Performance
Prefer to manipulate data in bulk with methods that return slices.
Example
use bit_mask_ring_buf::BMRingBuf; let mut rb = BMRingBuf::<u32>::from_len(4); rb[0] = 1; rb[1] = 2; rb[2] = 3; rb[3] = 4; let mut i = -3; assert_eq!(*rb.at(&mut i), 2); assert_eq!(i, 1);
pub fn at_mut(&mut self, i: &mut isize) -> &mut T
[src]
Returns the element at the index of type usize
as mutable while also
constraining the index i
. This is slightly more efficient
than calling both methods individually.
Performance
Prefer to manipulate data in bulk with methods that return slices.
Example
use bit_mask_ring_buf::BMRingBuf; let mut rb = BMRingBuf::<u32>::from_len(4); let mut i = -3; *rb.at_mut(&mut i) = 2; assert_eq!(rb[1], 2); assert_eq!(i, 1);
Trait Implementations
impl<T: Clone + Copy + Default> Clone for BMRingBuf<T>
[src]
impl<T: Debug + Copy + Clone + Default> Debug for BMRingBuf<T>
[src]
impl<T: Copy + Clone + Default> Index<isize> for BMRingBuf<T>
[src]
impl<T: Copy + Clone + Default> IndexMut<isize> for BMRingBuf<T>
[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for BMRingBuf<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for BMRingBuf<T> where
T: Send,
T: Send,
impl<T> Sync for BMRingBuf<T> where
T: Sync,
T: Sync,
impl<T> Unpin for BMRingBuf<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for BMRingBuf<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,