diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /vendor/byte-tools/src/lib.rs | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/byte-tools/src/lib.rs')
-rw-r--r-- | vendor/byte-tools/src/lib.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/vendor/byte-tools/src/lib.rs b/vendor/byte-tools/src/lib.rs new file mode 100644 index 000000000..b4a450f9f --- /dev/null +++ b/vendor/byte-tools/src/lib.rs @@ -0,0 +1,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()); + } +} |