use std::ptr;
use crate::buffer;
pub trait Transfer {
unsafe fn copy_to(&self, target: *mut u8);
}
impl<T: Transfer + ?Sized> Transfer for &T {
unsafe fn copy_to(&self, target: *mut u8) {
unsafe { T::copy_to(self, target) };
}
}
impl Transfer for [u8] {
unsafe fn copy_to(&self, target: *mut u8) {
unsafe { ptr::copy_nonoverlapping(self.as_ptr(), target, self.len()) };
}
}
impl<const N: usize> Transfer for [&[u8]; N] {
unsafe fn copy_to(&self, target: *mut u8) {
unsafe { buffer::raw::IteratorExt::copy_to(self.iter().copied(), target) };
}
}
impl<I: Transfer> Transfer for (&[u8], I) {
unsafe fn copy_to(&self, target: *mut u8) {
unsafe {
Transfer::copy_to(self.0, target);
Transfer::copy_to(&self.1, target.add(self.0.len()));
}
}
}
impl<const P: usize, const N: usize> Transfer for ([u8; P], [&[u8]; N]) {
unsafe fn copy_to(&self, target: *mut u8) {
unsafe { Transfer::copy_to(&(self.0.as_slice(), &self.1), target) };
}
}