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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
use core::ops::ShrAssign;
use crate::form::ArrayForm;
use super::ArrayMeet;
#[const_trait]
pub trait ArrayShrAssign<T, const N: usize>: ArrayMeet<T, N>
{
/// Applies the [`>>=`](core::ops::ShrAssign) operator to all elements, copying the operand for each operation.
///
/// # Examples
///
/// ```rust
/// use array__ops::ops::*;
///
/// let mut a = [0b0, 0b1, 0b10, 0b11, 0b100, 0b101, 0b110, 0b111];
///
/// a.shr_assign_all(1);
///
/// assert_eq!(a, [0b0, 0b0, 0b1, 0b1, 0b10, 0b10, 0b11, 0b11]);
/// ```
fn shr_assign_all<Rhs>(&mut self, rhs: Rhs)
where
T: ShrAssign<Rhs>,
Rhs: Copy;
/// Asynchronously applies the [`<<=`](core::ops::ShlAssign) operator to all elements, copying the operand for each operation.
///
/// This way, each operation is a seperate `async` task that may be executed in parallel, but with some extra overhead.
///
/// # Examples
///
/// ```rust
/// use array__ops::ops::*;
///
/// # tokio_test::block_on(async {
/// let mut a = [0b0, 0b1, 0b10, 0b11, 0b100, 0b101, 0b110, 0b111];
///
/// a.shl_assign_all_async(1).await;
///
/// assert_eq!(a, [0b0, 0b10, 0b100, 0b110, 0b1000, 0b1010, 0b1100, 0b1110]);
/// # })
/// ```
async fn shr_assign_all_async<Rhs>(&mut self, rhs: Rhs)
where
T: ShrAssign<Rhs>,
Rhs: Copy;
fn shr_assign_each<Rhs>(&mut self, rhs: Rhs)
where
T: ShrAssign<Rhs::Elem>,
Rhs: ArrayForm<N>;
async fn shr_assign_each_async<Rhs>(&mut self, rhs: Rhs)
where
T: ShrAssign<Rhs::Elem>,
Rhs: ArrayForm<N>;
}
impl<T, const N: usize> ArrayShrAssign<T, N> for [T; N]
{
fn shr_assign_all<Rhs>(&mut self, rhs: Rhs)
where
T: ShrAssign<Rhs>,
Rhs: Copy
{
self.meet_all_mut(rhs, ShrAssign::shr_assign)
}
async fn shr_assign_all_async<Rhs>(&mut self, rhs: Rhs)
where
T: ShrAssign<Rhs>,
Rhs: Copy
{
self.meet_all_mut_async(rhs, async |x, rhs| x.shr_assign(rhs)).await
}
fn shr_assign_each<Rhs>(&mut self, rhs: Rhs)
where
T: ShrAssign<Rhs::Elem>,
Rhs: ArrayForm<N>
{
self.meet_each_mut(rhs, ShrAssign::shr_assign)
}
async fn shr_assign_each_async<Rhs>(&mut self, rhs: Rhs)
where
T: ShrAssign<Rhs::Elem>,
Rhs: ArrayForm<N>
{
self.meet_each_mut_async(rhs, async |x, rhs| x.shr_assign(rhs)).await
}
}