summaryrefslogtreecommitdiffstats
path: root/vendor/byte-tools/src/lib.rs
blob: b4a450f9fbde5a0ff1776a2149a34368d230200f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#![no_std]
use core::ptr;

/// Copy bytes from `src` to `dst`
///
/// Panics if `src.len() < dst.len()`
#[inline(always)]
pub fn copy(src: &[u8], dst: &mut [u8]) {
    assert!(dst.len() >= src.len());
    unsafe {
        ptr::copy_nonoverlapping(src.as_ptr(), dst.as_mut_ptr(), src.len());
    }
}

/// Zero all bytes in `dst`
#[inline(always)]
pub fn zero(dst: &mut [u8]) {
    unsafe {
        ptr::write_bytes(dst.as_mut_ptr(), 0, dst.len());
    }
}

/// Sets all bytes in `dst` equal to `value`
#[inline(always)]
pub fn set(dst: &mut [u8], value: u8) {
    unsafe {
        ptr::write_bytes(dst.as_mut_ptr(), value, dst.len());
    }
}