You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
videl/src/util.rs

40 lines
663 B

4 years ago
//! Utility functions
use std::{
borrow::{
Borrow,
ToOwned,
},
};
/// Copy slice `src` into `dst` and return the number of elements copied.
#[inline] pub fn copy_slice<T,U,V,W,X>(mut dst: V, src: W) -> usize
where V: AsMut<[T]>,
W: AsRef<[U]>,
U: ToOwned<Owned=X>,
X: Borrow<U> + Into<T>
{
let mut i=0;
for (d, s) in dst.as_mut().iter_mut().zip(src.as_ref().iter())
{
*d = s.to_owned().into();
i+=1
}
i
}
#[cfg(test)]
mod tests
{
#[test]
fn copy_slice()
{
let mut to = [0u8; 40];
let from = [10u8; 37];
assert_eq!(super::copy_slice(&mut to, &from), 37);
assert_eq!(from, &to[0..37]);
}
}