Skip to content

Commit 8234211

Browse files
committed
Add fn for creating Box<[u8]> buffer
1 parent d398358 commit 8234211

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,6 @@ macro_rules! create_buffer {
345345
0
346346
$(
347347
+ $val.encoded_size()?
348-
349348
)*
350349
);
351350
vec![0; len]
@@ -441,6 +440,12 @@ macro_rules! map_first {
441440
(mapped, two)
442441
}};
443442
}
443+
444+
/// Returns a zerod `Box<[u8]>` where the slice is of length `encoded_size`.
445+
pub fn fixed_buffer_from_encoded_size(encoded_size: usize) -> Box<[u8]> {
446+
vec![0; encoded_size].into_boxed_slice()
447+
}
448+
444449
/// Split a slice in two at `mid`. Returns encoding error when `mid` is out of bounds.
445450
pub fn get_slices_checked(buffer: &[u8], mid: usize) -> Result<(&[u8], &[u8]), EncodingError> {
446451
buffer.split_at_checked(mid).ok_or_else(|| {

0 commit comments

Comments
 (0)