split_owned 0.1.0

simple way to split array in 2 owned arrays with compile-time bounds checks
Documentation
  • Coverage
  • 66.67%
    2 out of 3 items documented1 out of 3 items with examples
  • Size
  • Source code size: 6.37 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 209.36 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 8s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • IoaNNUwU/split_owned
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • IoaNNUwU

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.)]);