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

#1339 in Rust patterns

Download history 1593/week @ 2024-08-06 1790/week @ 2024-08-13 1804/week @ 2024-08-20 1895/week @ 2024-08-27 1797/week @ 2024-09-03 1545/week @ 2024-09-10 1369/week @ 2024-09-17 1441/week @ 2024-09-24 1664/week @ 2024-10-01 1075/week @ 2024-10-08 1438/week @ 2024-10-15 1376/week @ 2024-10-22 1176/week @ 2024-10-29 1078/week @ 2024-11-05 708/week @ 2024-11-12 1365/week @ 2024-11-19

4,733 downloads per month
Used in 6 crates (2 directly)

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