1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
use array_trait::Array;
use slice_ops::AsSlice;
use crate::private;
#[const_trait]
pub trait ArrayChain<T, const N: usize>: Array + AsSlice<Item = T>
{
/// Chains two arrays with the same item together.
///
/// # Example
///
/// ```rust
/// #![feature(generic_const_exprs)]
///
/// use array__ops::ops::*;
///
/// let a = ["one", "two"];
/// let b = ["three"];
///
/// assert_eq!(a.chain(b), ["one", "two", "three"]);
/// ```
fn chain<const M: usize>(self, rhs: [T; M]) -> [T; N + M];
/// Chains two arrays with the same item together in reverse.
///
/// # Example
/// ```rust
/// #![feature(generic_const_exprs)]
///
/// use array__ops::ops::*;
///
/// let a = ["two", "three"];
/// let b = ["one"];
///
/// assert_eq!(a.rchain(b), ["one", "two", "three"]);
/// ```
fn rchain<const M: usize>(self, lhs: [T; M]) -> [T; N + M];
}
impl<T, const N: usize> const ArrayChain<T, N> for [T; N]
{
fn chain<const M: usize>(self, rhs: [T; M]) -> [T; N + M]
{
unsafe {
private::merge_transmute(self, rhs)
}
}
fn rchain<const M: usize>(self, lhs: [T; M]) -> [T; N + M]
{
unsafe {
private::merge_transmute(lhs, self)
}
}
}
#[cfg(test)]
mod test
{
use crate::ops::*;
#[test]
fn it_works()
{
let a = ["one", "two"];
let b = ["three"];
assert_eq!(a.chain(b), ["one", "two", "three"]);
}
}