3 releases (breaking)

Uses old Rust 2015

0.3.0 Jan 4, 2023
0.2.0 Feb 14, 2018
0.1.0 Feb 10, 2018

#2151 in Rust patterns

Download history 268/week @ 2023-11-27 209/week @ 2023-12-04 203/week @ 2023-12-11 202/week @ 2023-12-18 161/week @ 2023-12-25 187/week @ 2024-01-01 219/week @ 2024-01-08 272/week @ 2024-01-15 235/week @ 2024-01-22 248/week @ 2024-01-29 285/week @ 2024-02-05 309/week @ 2024-02-12 280/week @ 2024-02-19 289/week @ 2024-02-26 453/week @ 2024-03-04 216/week @ 2024-03-11

1,272 downloads per month
Used in 3 crates (via vex-rt)

MIT license

5KB

slice-copy

Build Status Crates.io Documentation

Go style copying for slices. For times where you would rather use the amount copied to adjust your slices as opposed to determining the amount to copy, adjusting your slices, and finally copying.

use slice_copy::copy;

let mut l = b"hello".to_vec();
let r = b"goodbye".to_vec();

let n = copy(&mut l, &r);

assert_eq!(n, 5);
assert_eq!(l, b"goodb");

lib.rs:

This crate provides Go style copying / cloning for slices.

This crate is for those times where it is easier to adjust slices based off the number of elements copied, as opposed to determining the amount to copy before adjusting slices and finally copying.

Examples

We can use copy for types that implement Copy.

use slice_copy::copy;

let mut l = b"hello".to_vec();
let r = b"goodbye".to_vec();

let n = copy(&mut l, &r);

assert_eq!(n, 5);
assert_eq!(l, b"goodb");

Similarly, we can use clone for types that implement Clone.

use slice_copy::clone;

let mut l = b"foobarbaz".to_vec();
let r = b"biz".to_vec();

let n = clone(&mut l, &r);

assert_eq!(n, 3);
assert_eq!(l, b"bizbarbaz");

No runtime deps