byte_tools/lib.rs
1#![no_std]
2use core::ptr;
3
4/// Copy bytes from `src` to `dst`
5///
6/// Panics if `src.len() < dst.len()`
7#[inline(always)]
8pub fn copy(src: &[u8], dst: &mut [u8]) {
9 assert!(dst.len() >= src.len());
10 unsafe {
11 ptr::copy_nonoverlapping(src.as_ptr(), dst.as_mut_ptr(), src.len());
12 }
13}
14
15/// Zero all bytes in `dst`
16#[inline(always)]
17pub fn zero(dst: &mut [u8]) {
18 unsafe {
19 ptr::write_bytes(dst.as_mut_ptr(), 0, dst.len());
20 }
21}
22
23/// Sets all bytes in `dst` equal to `value`
24#[inline(always)]
25pub fn set(dst: &mut [u8], value: u8) {
26 unsafe {
27 ptr::write_bytes(dst.as_mut_ptr(), value, dst.len());
28 }
29}