split_owned

Crates.iosplit_owned
lib.rssplit_owned
version
sourcesrc
created_at2024-12-11 17:36:54.736206
updated_at2024-12-11 17:42:15.523506
descriptionsimple way to split array in 2 owned arrays with compile-time bounds checks
homepage
repositoryhttps://github.com/IoaNNUwU/split_owned
max_upload_size
id1480370
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`
size0
(IoaNNUwU)

documentation

README

This crate provides simple way to split array in 2 owned arrays with compile-time bounds checks.

  • Works with Non-Copy & Non-Clone types

Common 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.)]);
Commit count: 5

cargo fmt