utils: move damage algorithms to algorithm crate
This commit is contained in:
parent
259340938b
commit
6e244a08ab
12 changed files with 710 additions and 542 deletions
9
algorithms/Cargo.toml
Normal file
9
algorithms/Cargo.toml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
[package]
|
||||
name = "algorithms"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
smallvec = { version = "1.8.0", features = ["const_generics", "const_new", "union"] }
|
||||
5
algorithms/src/lib.rs
Normal file
5
algorithms/src/lib.rs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#![feature(generic_associated_types)]
|
||||
|
||||
pub mod qoi;
|
||||
pub mod rect;
|
||||
mod windows;
|
||||
91
algorithms/src/qoi.rs
Normal file
91
algorithms/src/qoi.rs
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
pub fn xrgb8888_encode_qoi(bytes: &[u8], width: u32, height: u32, stride: u32) -> Vec<u8> {
|
||||
const OP_RGB: u8 = 0b1111_1110;
|
||||
const OP_INDEX: u8 = 0b0000_0000;
|
||||
const OP_DIFF: u8 = 0b0100_0000;
|
||||
const OP_LUMA: u8 = 0b1000_0000;
|
||||
const OP_RUN: u8 = 0b1100_0000;
|
||||
|
||||
let mut res = vec![];
|
||||
let width_bytes_be = width.to_be_bytes();
|
||||
let height_bytes_be = height.to_be_bytes();
|
||||
let header = [
|
||||
b'q',
|
||||
b'o',
|
||||
b'i',
|
||||
b'f',
|
||||
width_bytes_be[0],
|
||||
width_bytes_be[1],
|
||||
width_bytes_be[2],
|
||||
width_bytes_be[3],
|
||||
height_bytes_be[0],
|
||||
height_bytes_be[1],
|
||||
height_bytes_be[2],
|
||||
height_bytes_be[3],
|
||||
3,
|
||||
0,
|
||||
];
|
||||
res.extend_from_slice(&header);
|
||||
let mut prev_pixel = [0, 0, 0, 0xff];
|
||||
let mut array = [[0; 4]; 64];
|
||||
let mut run_length = 0;
|
||||
for line in bytes.chunks_exact(stride as _) {
|
||||
for &pixel in array_chunks::<_, 4>(&line[..(width * 4) as _]) {
|
||||
let pixel = [pixel[2], pixel[1], pixel[0], 0xff];
|
||||
if pixel == prev_pixel {
|
||||
run_length += 1;
|
||||
if run_length == 62 {
|
||||
res.push(OP_RUN | (run_length - 1));
|
||||
run_length = 0;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if run_length > 0 {
|
||||
res.push(OP_RUN | (run_length - 1));
|
||||
run_length = 0;
|
||||
}
|
||||
let prev = prev_pixel;
|
||||
prev_pixel = pixel;
|
||||
let index = {
|
||||
let sum = 0u8
|
||||
.wrapping_add(pixel[0].wrapping_mul(3))
|
||||
.wrapping_add(pixel[1].wrapping_mul(5))
|
||||
.wrapping_add(pixel[2].wrapping_mul(7))
|
||||
.wrapping_add(255u8.wrapping_mul(11));
|
||||
sum & 63
|
||||
};
|
||||
if array[index as usize] == pixel {
|
||||
res.push(OP_INDEX | index);
|
||||
continue;
|
||||
}
|
||||
array[index as usize] = pixel;
|
||||
let dr = pixel[0].wrapping_sub(prev[0]);
|
||||
let dg = pixel[1].wrapping_sub(prev[1]);
|
||||
let db = pixel[2].wrapping_sub(prev[2]);
|
||||
let dr_2 = dr.wrapping_add(2);
|
||||
let dg_2 = dg.wrapping_add(2);
|
||||
let db_2 = db.wrapping_add(2);
|
||||
if dr_2 | dg_2 | db_2 | 3 == 3 {
|
||||
res.push(OP_DIFF | (dr_2 << 4) | (dg_2 << 2) | db_2);
|
||||
continue;
|
||||
}
|
||||
let dr_dg_8 = dr.wrapping_sub(dg).wrapping_add(8);
|
||||
let db_dg_8 = db.wrapping_sub(dg).wrapping_add(8);
|
||||
let dg_32 = dg.wrapping_add(32);
|
||||
if (dg_32 | 63 == 63) && (dr_dg_8 | db_dg_8 | 15 == 15) {
|
||||
res.extend_from_slice(&[OP_LUMA | dg_32, (dr_dg_8 << 4) | db_dg_8]);
|
||||
continue;
|
||||
}
|
||||
res.extend_from_slice(&[OP_RGB, pixel[0], pixel[1], pixel[2]]);
|
||||
}
|
||||
}
|
||||
if run_length > 0 {
|
||||
res.push(OP_RUN | (run_length - 1));
|
||||
}
|
||||
res.extend_from_slice(&[0, 0, 0, 0, 0, 0, 0, 1]);
|
||||
res
|
||||
}
|
||||
|
||||
fn array_chunks<T, const N: usize>(slice: &[T]) -> &[[T; N]] {
|
||||
let len = slice.len() / N;
|
||||
unsafe { std::slice::from_raw_parts(slice.as_ptr() as _, len) }
|
||||
}
|
||||
35
algorithms/src/rect.rs
Normal file
35
algorithms/src/rect.rs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
pub mod region;
|
||||
|
||||
use {
|
||||
smallvec::SmallVec,
|
||||
std::fmt::{Debug, Formatter},
|
||||
};
|
||||
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Default)]
|
||||
pub struct RectRaw {
|
||||
pub x1: i32,
|
||||
pub y1: i32,
|
||||
pub x2: i32,
|
||||
pub y2: i32,
|
||||
}
|
||||
|
||||
impl Debug for RectRaw {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("Rect")
|
||||
.field("x1", &self.x1)
|
||||
.field("y1", &self.y1)
|
||||
.field("x2", &self.x2)
|
||||
.field("y2", &self.y2)
|
||||
.field("width", &(self.x2 - self.x1))
|
||||
.field("height", &(self.y2 - self.y1))
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl RectRaw {
|
||||
fn is_empty(&self) -> bool {
|
||||
self.x1 == self.x2 || self.y1 == self.y2
|
||||
}
|
||||
}
|
||||
|
||||
type Container = SmallVec<[RectRaw; 1]>;
|
||||
466
algorithms/src/rect/region.rs
Normal file
466
algorithms/src/rect/region.rs
Normal file
|
|
@ -0,0 +1,466 @@
|
|||
use {
|
||||
crate::{
|
||||
rect::{Container, RectRaw},
|
||||
windows::WindowsExt,
|
||||
},
|
||||
std::{cmp::Ordering, collections::BinaryHeap, mem, ops::Deref},
|
||||
};
|
||||
|
||||
pub fn union(left: &Container, right: &Container) -> Container {
|
||||
op::<Union>(left, &right)
|
||||
}
|
||||
|
||||
pub fn subtract(left: &Container, right: &Container) -> Container {
|
||||
op::<Subtract>(left, right)
|
||||
}
|
||||
|
||||
struct Bands<'a> {
|
||||
rects: &'a [RectRaw],
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
struct Band<'a> {
|
||||
rects: &'a [RectRaw],
|
||||
y1: i32,
|
||||
y2: i32,
|
||||
}
|
||||
|
||||
impl<'a> Band<'a> {
|
||||
fn can_merge_with(&self, next: &Band) -> bool {
|
||||
next.rects.len() == self.rects.len()
|
||||
&& next.y1 == self.y2
|
||||
&& next
|
||||
.rects
|
||||
.iter()
|
||||
.zip(self.rects.iter())
|
||||
.all(|(a, b)| (a.x1, a.x2) == (b.x1, b.x2))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Iterator for Bands<'a> {
|
||||
type Item = Band<'a>;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
if self.rects.is_empty() {
|
||||
return None;
|
||||
}
|
||||
let y1 = self.rects[0].y1;
|
||||
let y2 = self.rects[0].y2;
|
||||
for (pos, rect) in self.rects[1..].iter().enumerate() {
|
||||
if rect.y1 != y1 {
|
||||
let (res, rects) = self.rects.split_at(pos + 1);
|
||||
self.rects = rects;
|
||||
return Some(Band { rects: res, y1, y2 });
|
||||
}
|
||||
}
|
||||
Some(Band {
|
||||
rects: mem::replace(&mut self.rects, &[]),
|
||||
y1,
|
||||
y2,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn extents(a: &[RectRaw]) -> RectRaw {
|
||||
let mut a = a.iter();
|
||||
let mut res = match a.next() {
|
||||
Some(a) => *a,
|
||||
_ => return RectRaw::default(),
|
||||
};
|
||||
for a in a {
|
||||
res.x1 = res.x1.min(a.x1);
|
||||
res.y1 = res.y1.min(a.y1);
|
||||
res.x2 = res.x2.max(a.x2);
|
||||
res.y2 = res.y2.max(a.y2);
|
||||
}
|
||||
res
|
||||
}
|
||||
|
||||
fn op<O: Op>(a: &[RectRaw], b: &[RectRaw]) -> Container {
|
||||
let mut res = Container::new();
|
||||
|
||||
let mut prev_band_y2 = 0;
|
||||
let mut prev_band_start = 0;
|
||||
let mut cur_band_start;
|
||||
|
||||
let mut a_bands = Bands { rects: a };
|
||||
let mut b_bands = Bands { rects: b };
|
||||
|
||||
let mut a_opt = a_bands.next();
|
||||
let mut b_opt = b_bands.next();
|
||||
|
||||
macro_rules! fixup_new_band {
|
||||
($y1:expr, $y2:expr) => {{
|
||||
if prev_band_y2 != $y1 || !coalesce(&mut res, prev_band_start, cur_band_start, $y2) {
|
||||
prev_band_start = cur_band_start;
|
||||
}
|
||||
prev_band_y2 = $y2;
|
||||
}};
|
||||
}
|
||||
|
||||
macro_rules! append_nonoverlapping {
|
||||
($append_opt:expr, $a:expr, $a_opt:expr, $a_bands:expr, $b:expr) => {{
|
||||
if $append_opt {
|
||||
let y2 = $a.y2.min($b.y1);
|
||||
cur_band_start = res.len();
|
||||
res.reserve($a.rects.len());
|
||||
for rect in $a.rects {
|
||||
res.push(RectRaw {
|
||||
x1: rect.x1,
|
||||
y1: $a.y1,
|
||||
x2: rect.x2,
|
||||
y2,
|
||||
});
|
||||
}
|
||||
fixup_new_band!($a.y1, y2);
|
||||
}
|
||||
if $a.y2 <= $b.y1 {
|
||||
$a_opt = $a_bands.next();
|
||||
} else {
|
||||
$a.y1 = $b.y1;
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
while let (Some(a), Some(b)) = (&mut a_opt, &mut b_opt) {
|
||||
if a.y1 < b.y1 {
|
||||
append_nonoverlapping!(O::APPEND_NON_A, a, a_opt, a_bands, b);
|
||||
} else if b.y1 < a.y1 {
|
||||
append_nonoverlapping!(O::APPEND_NON_B, b, b_opt, b_bands, a);
|
||||
} else {
|
||||
let y2 = a.y2.min(b.y2);
|
||||
cur_band_start = res.len();
|
||||
O::handle_band(&mut res, a.rects, b.rects, a.y1, y2);
|
||||
if res.len() > cur_band_start {
|
||||
fixup_new_band!(a.y1, y2);
|
||||
}
|
||||
if a.y2 == y2 {
|
||||
a_opt = a_bands.next();
|
||||
} else {
|
||||
a.y1 = y2;
|
||||
}
|
||||
if b.y2 == y2 {
|
||||
b_opt = b_bands.next();
|
||||
} else {
|
||||
b.y1 = y2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! push_trailing {
|
||||
($a_opt:expr, $a_bands:expr) => {{
|
||||
while let Some(a) = $a_opt {
|
||||
cur_band_start = res.len();
|
||||
res.reserve(a.rects.len());
|
||||
for rect in a.rects {
|
||||
res.push(RectRaw {
|
||||
x1: rect.x1,
|
||||
y1: a.y1,
|
||||
x2: rect.x2,
|
||||
y2: a.y2,
|
||||
});
|
||||
}
|
||||
fixup_new_band!(a.y1, a.y2);
|
||||
$a_opt = $a_bands.next();
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
if O::APPEND_NON_A {
|
||||
push_trailing!(a_opt, a_bands);
|
||||
}
|
||||
|
||||
if O::APPEND_NON_B {
|
||||
push_trailing!(b_opt, b_bands);
|
||||
}
|
||||
|
||||
res.shrink_to_fit();
|
||||
res
|
||||
}
|
||||
|
||||
fn coalesce(new: &mut Container, a: usize, b: usize, y2: i32) -> bool {
|
||||
if new.len() - b != b - a {
|
||||
return false;
|
||||
}
|
||||
let slice_a = &new[a..b];
|
||||
let slice_b = &new[b..];
|
||||
for (a, b) in slice_a.iter().zip(slice_b.iter()) {
|
||||
if (a.x1, a.x2) != (b.x1, b.x2) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for rect in &mut new[a..b] {
|
||||
rect.y2 = y2;
|
||||
}
|
||||
new.truncate(b);
|
||||
true
|
||||
}
|
||||
|
||||
trait Op {
|
||||
const APPEND_NON_A: bool;
|
||||
const APPEND_NON_B: bool;
|
||||
|
||||
fn handle_band(new: &mut Container, a: &[RectRaw], b: &[RectRaw], y1: i32, y2: i32);
|
||||
}
|
||||
|
||||
struct Union;
|
||||
|
||||
impl Op for Union {
|
||||
const APPEND_NON_A: bool = true;
|
||||
const APPEND_NON_B: bool = true;
|
||||
|
||||
fn handle_band(new: &mut Container, mut a: &[RectRaw], mut b: &[RectRaw], y1: i32, y2: i32) {
|
||||
let mut x1;
|
||||
let mut x2;
|
||||
|
||||
macro_rules! push {
|
||||
() => {
|
||||
new.push(RectRaw { x1, y1, x2, y2 });
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! merge {
|
||||
($r:expr) => {
|
||||
if $r.x1 <= x2 {
|
||||
if $r.x2 > x2 {
|
||||
x2 = $r.x2;
|
||||
}
|
||||
} else {
|
||||
push!();
|
||||
x1 = $r.x1;
|
||||
x2 = $r.x2;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if a[0].x1 < b[0].x1 {
|
||||
x1 = a[0].x1;
|
||||
x2 = a[0].x2;
|
||||
a = &a[1..];
|
||||
} else {
|
||||
x1 = b[0].x1;
|
||||
x2 = b[0].x2;
|
||||
b = &b[1..];
|
||||
}
|
||||
|
||||
let mut a_iter = a.iter();
|
||||
let mut b_iter = b.iter();
|
||||
|
||||
let mut a_opt = a_iter.next();
|
||||
let mut b_opt = b_iter.next();
|
||||
|
||||
while let (Some(a), Some(b)) = (a_opt, b_opt) {
|
||||
if a.x1 < b.x1 {
|
||||
merge!(a);
|
||||
a_opt = a_iter.next();
|
||||
} else {
|
||||
merge!(b);
|
||||
b_opt = b_iter.next();
|
||||
}
|
||||
}
|
||||
|
||||
while let Some(a) = a_opt {
|
||||
merge!(a);
|
||||
a_opt = a_iter.next();
|
||||
}
|
||||
|
||||
while let Some(b) = b_opt {
|
||||
merge!(b);
|
||||
b_opt = b_iter.next();
|
||||
}
|
||||
|
||||
push!();
|
||||
}
|
||||
}
|
||||
|
||||
struct Subtract;
|
||||
|
||||
impl Op for Subtract {
|
||||
const APPEND_NON_A: bool = true;
|
||||
const APPEND_NON_B: bool = false;
|
||||
|
||||
fn handle_band(new: &mut Container, a: &[RectRaw], b: &[RectRaw], y1: i32, y2: i32) {
|
||||
let mut x1;
|
||||
let mut x2;
|
||||
|
||||
macro_rules! push {
|
||||
($x2:expr) => {
|
||||
new.push(RectRaw {
|
||||
x1,
|
||||
y1,
|
||||
x2: $x2,
|
||||
y2,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
let mut a_iter = a.iter();
|
||||
let mut b_iter = b.iter();
|
||||
|
||||
macro_rules! pull {
|
||||
() => {
|
||||
match a_iter.next() {
|
||||
Some(n) => {
|
||||
x1 = n.x1;
|
||||
x2 = n.x2;
|
||||
}
|
||||
_ => return,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
pull!();
|
||||
|
||||
let mut b_opt = b_iter.next();
|
||||
|
||||
while let Some(b) = b_opt {
|
||||
if b.x2 <= x1 {
|
||||
b_opt = b_iter.next();
|
||||
} else if b.x1 >= x2 {
|
||||
push!(x2);
|
||||
pull!();
|
||||
} else {
|
||||
if b.x1 > x1 {
|
||||
push!(b.x1);
|
||||
}
|
||||
if b.x2 < x2 {
|
||||
x1 = b.x2;
|
||||
} else {
|
||||
pull!();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
loop {
|
||||
push!(x2);
|
||||
pull!();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn rects_to_bands(rects_tmp: &[RectRaw]) -> Container {
|
||||
#[derive(Copy, Clone)]
|
||||
struct W(RectRaw);
|
||||
impl Eq for W {}
|
||||
impl PartialEq<Self> for W {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.0 == other.0
|
||||
}
|
||||
}
|
||||
impl PartialOrd<Self> for W {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
Some(self.cmp(other))
|
||||
}
|
||||
}
|
||||
impl Ord for W {
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
self.0
|
||||
.y1
|
||||
.cmp(&other.0.y1)
|
||||
.then_with(|| self.0.x1.cmp(&other.0.x1))
|
||||
.reverse()
|
||||
}
|
||||
}
|
||||
impl Deref for W {
|
||||
type Target = RectRaw;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
let ys = {
|
||||
let mut tmp: Vec<_> = rects_tmp.iter().flat_map(|r| [r.y1, r.y2]).collect();
|
||||
tmp.sort_unstable();
|
||||
let mut last = None;
|
||||
let mut res = vec![];
|
||||
for y in tmp {
|
||||
if Some(y) != last {
|
||||
last = Some(y);
|
||||
res.push(y);
|
||||
}
|
||||
}
|
||||
res
|
||||
};
|
||||
|
||||
let mut rects = BinaryHeap::with_capacity(rects_tmp.len());
|
||||
for rect in rects_tmp.iter().copied() {
|
||||
if !rect.is_empty() {
|
||||
rects.push(W(rect));
|
||||
}
|
||||
}
|
||||
|
||||
let mut res = Container::new();
|
||||
|
||||
for &[y1, y2] in ys.array_windows_ext::<2>() {
|
||||
loop {
|
||||
macro_rules! check_rect {
|
||||
($rect:expr) => {{
|
||||
if $rect.y1 != y1 {
|
||||
break;
|
||||
}
|
||||
rects.pop();
|
||||
if y2 < $rect.y2 {
|
||||
$rect.0.y1 = y2;
|
||||
rects.push($rect);
|
||||
}
|
||||
}};
|
||||
}
|
||||
if let Some(mut rect) = rects.peek().copied() {
|
||||
check_rect!(rect);
|
||||
let mut x1 = rect.x1;
|
||||
let mut x2 = rect.x2;
|
||||
while let Some(mut rect) = rects.peek().copied() {
|
||||
check_rect!(rect);
|
||||
if rect.x1 > x2 {
|
||||
res.push(RectRaw { x1, x2, y1, y2 });
|
||||
x1 = rect.x1;
|
||||
x2 = rect.x2;
|
||||
} else {
|
||||
x2 = x2.max(rect.x2);
|
||||
}
|
||||
}
|
||||
res.push(RectRaw { x1, x2, y1, y2 });
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
let mut needs_merge = false;
|
||||
let mut num_elements = res.len();
|
||||
let mut bands = Bands { rects: &res }.peekable();
|
||||
while let Some(band) = bands.next() {
|
||||
let next = match bands.peek() {
|
||||
Some(next) => next,
|
||||
_ => break,
|
||||
};
|
||||
if band.can_merge_with(next) {
|
||||
needs_merge = true;
|
||||
num_elements -= band.rects.len();
|
||||
}
|
||||
}
|
||||
|
||||
if !needs_merge {
|
||||
res.shrink_to_fit();
|
||||
return res;
|
||||
}
|
||||
|
||||
let mut merged = Container::with_capacity(num_elements);
|
||||
let mut bands = Bands { rects: &res }.peekable();
|
||||
while let Some(mut band) = bands.next() {
|
||||
while let Some(next) = bands.peek() {
|
||||
if band.can_merge_with(next) {
|
||||
band.y2 = next.y2;
|
||||
bands.next();
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
for mut rect in band.rects.iter().copied() {
|
||||
rect.y2 = band.y2;
|
||||
merged.push(rect);
|
||||
}
|
||||
}
|
||||
|
||||
merged
|
||||
}
|
||||
35
algorithms/src/windows.rs
Normal file
35
algorithms/src/windows.rs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
pub trait WindowsExt<T> {
|
||||
type Windows<'a, const N: usize>: Iterator<Item = &'a [T; N]>
|
||||
where
|
||||
Self: 'a,
|
||||
T: 'a;
|
||||
|
||||
fn array_windows_ext<'a, const N: usize>(&'a self) -> Self::Windows<'a, N>;
|
||||
}
|
||||
|
||||
impl<T> WindowsExt<T> for [T] {
|
||||
type Windows<'a, const N: usize> = WindowsIter<'a, T, N> where T: 'a;
|
||||
|
||||
fn array_windows_ext<'a, const N: usize>(&'a self) -> Self::Windows<'a, N> {
|
||||
WindowsIter { slice: self }
|
||||
}
|
||||
}
|
||||
|
||||
pub struct WindowsIter<'a, T, const N: usize> {
|
||||
slice: &'a [T],
|
||||
}
|
||||
|
||||
impl<'a, T, const N: usize> Iterator for WindowsIter<'a, T, N> {
|
||||
type Item = &'a [T; N];
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
if self.slice.len() < N {
|
||||
return None;
|
||||
}
|
||||
let res = unsafe { &*self.slice.as_ptr().cast::<[T; N]>() };
|
||||
if N > 0 {
|
||||
self.slice = &self.slice[1..];
|
||||
}
|
||||
Some(res)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue