Skip to content

Commit bc83c8f

Browse files
authored
Add Array::resize_raw. (#32)
This commit adds a new method Array::resize_raw that changes the size of the octets sequence inside and array without updating the content.
1 parent d49d28c commit bc83c8f

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/array.rs

+17
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! A fixed-capacity octets sequence.
12
23
use core::{cmp, fmt};
34
use core::ops::RangeBounds;
@@ -31,6 +32,22 @@ impl<const N: usize> Array<N> {
3132
pub fn as_slice_mut(&mut self) -> &mut [u8] {
3233
&mut self.octets[..self.len]
3334
}
35+
36+
/// Resizes the array in place updating additional octets.
37+
///
38+
/// The method only changes the length of the contained octets
39+
/// sequence. If `new_len` is greater than the current length, the
40+
/// content of the additional octets will be left at whatever they
41+
/// were.
42+
///
43+
/// # Panics
44+
///
45+
/// The method panics if `new_len` is larger than the array size
46+
/// `const N`.
47+
pub fn resize_raw(&mut self, new_len: usize) {
48+
assert!(new_len < N);
49+
self.len = new_len
50+
}
3451
}
3552

3653

0 commit comments

Comments
 (0)