1use crate::{layout::Layout, str::check_char_boundary, ArcSlice, ArcSliceMut, ArcStr};
2
3impl<L: Layout> bytes::Buf for ArcSlice<u8, L> {
4 fn remaining(&self) -> usize {
5 self.len()
6 }
7
8 fn chunk(&self) -> &[u8] {
9 self.as_slice()
10 }
11
12 fn advance(&mut self, cnt: usize) {
13 self.advance(cnt);
14 }
15}
16
17impl bytes::Buf for ArcSliceMut<u8> {
18 fn remaining(&self) -> usize {
19 self.len()
20 }
21
22 fn chunk(&self) -> &[u8] {
23 self.as_slice()
24 }
25
26 fn advance(&mut self, cnt: usize) {
27 self.advance(cnt);
28 }
29}
30
31unsafe impl bytes::BufMut for ArcSliceMut<u8> {
32 fn remaining_mut(&self) -> usize {
33 self.capacity() - self.len()
34 }
35
36 unsafe fn advance_mut(&mut self, cnt: usize) {
37 unsafe { self.set_len(self.len() + cnt) }
39 }
40
41 fn chunk_mut(&mut self) -> &mut bytes::buf::UninitSlice {
42 unsafe { self.spare_capacity_mut() }.into()
44 }
45}
46
47impl<L: Layout> bytes::Buf for ArcStr<L> {
48 fn remaining(&self) -> usize {
49 self.len()
50 }
51
52 fn chunk(&self) -> &[u8] {
53 self.as_ref()
54 }
55
56 fn advance(&mut self, cnt: usize) {
57 self.advance(cnt);
58 }
59}
60
61#[cfg(feature = "inlined")]
62impl<L: Layout> bytes::Buf for crate::inlined::SmallBytes<L> {
63 fn remaining(&self) -> usize {
64 self.len()
65 }
66
67 fn chunk(&self) -> &[u8] {
68 self.as_slice()
69 }
70
71 fn advance(&mut self, cnt: usize) {
72 self.advance(cnt);
73 }
74}
75
76#[cfg(feature = "inlined")]
77impl<L: Layout> bytes::Buf for crate::inlined::SmallArcBytes<L> {
78 fn remaining(&self) -> usize {
79 self.len()
80 }
81
82 fn chunk(&self) -> &[u8] {
83 self
84 }
85
86 fn advance(&mut self, cnt: usize) {
87 match self.as_either_mut() {
88 either::Either::Left(bytes) => bytes.advance(cnt),
89 either::Either::Right(bytes) => bytes.advance(cnt),
90 }
91 }
92}
93
94#[cfg(feature = "inlined")]
95impl<L: Layout> bytes::Buf for crate::inlined::SmallArcStr<L> {
96 fn remaining(&self) -> usize {
97 self.len()
98 }
99
100 fn chunk(&self) -> &[u8] {
101 self.as_ref()
102 }
103
104 fn advance(&mut self, cnt: usize) {
105 check_char_boundary(self, cnt);
106 match self.as_either_mut() {
107 either::Either::Left(s) => s.advance(cnt),
108 either::Either::Right(s) => s.advance(cnt),
109 }
110 }
111}