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
use {
core::{
ops::Deref,
sync::atomic::AtomicUsize,
},
std::sync::Arc,
crate::Counter,
};
mod tests;
#[derive(Debug)]
pub struct Bytes {
bytes: Vec<u8>,
counter: Counter,
}
impl Bytes {
pub (crate) fn new(bytes: Vec<u8>, counter: Arc<AtomicUsize>) -> Self {
let counter = Counter::new(bytes.len(), counter);
Self {
bytes,
counter,
}
}
}
impl Deref for Bytes {
type Target = [u8];
fn deref(&self) -> &Self::Target {
&self.bytes
}
}
impl From<Bytes> for Vec<u8> {
fn from(bytes: Bytes) -> Self {
bytes.bytes
}
}