Crates.io | split_owned |
lib.rs | split_owned |
version | |
source | src |
created_at | 2024-12-11 17:36:54.736206 |
updated_at | 2024-12-11 17:42:15.523506 |
description | simple way to split array in 2 owned arrays with compile-time bounds checks |
homepage | |
repository | https://github.com/IoaNNUwU/split_owned |
max_upload_size | |
id | 1480370 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Non-Copy
& Non-Clone
typesCommon usage:
use split_owned::SplitOwned;
let arr: [i32; 7] = [0, 1, 2, 3, 4, 5, 6];
let (arr1, arr2) = arr.split_owned::<3, 4>();
assert_eq!(arr1, [0, 1, 2]);
assert_eq!(arr2, [3, 4, 5, 6]);
use split_owned::SplitOwned;
let arr: [i32; 7] = [0, 1, 2, 3, 4, 5, 6];
let arr1: [i32; 3];
let arr2: [i32; 4];
(arr1, arr2) = arr.split_owned();
assert_eq!(arr1, [0, 1, 2]);
assert_eq!(arr2, [3, 4, 5, 6]);
Does not compile
use split_owned::SplitOwned;
let arr: [i32; 7] = [0, 1, 2, 3, 4, 5, 6];
// Compile error:
// Length of original array has to be equal to sum of lengths of resulting arrays N == K + L
let (arr1, arr2) = arr.split_owned::<2, 4>();
Non-Clone
type
use split_owned::SplitOwned;
#[derive(Debug, PartialEq)]
struct Num(f64);
let arr: [Num; 7] = [Num(0.), Num(1.), Num(2.), Num(3.), Num(4.), Num(5.), Num(6.)];
let (arr1, arr2) = arr.split_owned::<3, 4>();
assert_eq!(arr1, [Num(0.), Num(1.), Num(2.)]);
assert_eq!(arr2, [Num(3.), Num(4.), Num(5.), Num(6.)]);