radix_rust/slice.rs
1use crate::rust::vec::Vec;
2
3/// Copies a slice to a fixed-sized array.
4pub fn copy_u8_array<const N: usize>(slice: &[u8]) -> [u8; N] {
5 if slice.len() == N {
6 let mut bytes = [0u8; N];
7 bytes.copy_from_slice(slice);
8 bytes
9 } else {
10 panic!("Invalid length: expected {}, actual {}", N, slice.len());
11 }
12}
13
14/// Combines a u8 with a u8 slice.
15pub fn combine(ty: u8, bytes: &[u8]) -> Vec<u8> {
16 let mut v = Vec::with_capacity(1 + bytes.len());
17 v.push(ty);
18 v.extend(bytes);
19 v
20}