1use crate::{Buf, BufMut, Channel, ChannelMut, ExactSizeBuf, ReadBuf};
2
3pub struct Skip<B> {
7 buf: B,
8 n: usize,
9}
10
11impl<B> Skip<B> {
12 pub(crate) fn new(buf: B, n: usize) -> Self {
14 Self { buf, n }
15 }
16}
17
18impl<B> Buf for Skip<B>
35where
36 B: Buf,
37{
38 type Sample = B::Sample;
39
40 type Channel<'this>
41 = B::Channel<'this>
42 where
43 Self: 'this;
44
45 type IterChannels<'this>
46 = IterChannels<B::IterChannels<'this>>
47 where
48 Self: 'this;
49
50 fn frames_hint(&self) -> Option<usize> {
51 let frames = self.buf.frames_hint()?;
52 Some(frames.saturating_sub(self.n))
53 }
54
55 fn channels(&self) -> usize {
56 self.buf.channels()
57 }
58
59 fn get_channel(&self, channel: usize) -> Option<Self::Channel<'_>> {
60 Some(self.buf.get_channel(channel)?.skip(self.n))
61 }
62
63 fn iter_channels(&self) -> Self::IterChannels<'_> {
64 IterChannels {
65 iter: self.buf.iter_channels(),
66 n: self.n,
67 }
68 }
69}
70
71impl<B> BufMut for Skip<B>
72where
73 B: BufMut,
74{
75 type ChannelMut<'a>
76 = B::ChannelMut<'a>
77 where
78 Self: 'a;
79
80 type IterChannelsMut<'a>
81 = IterChannelsMut<B::IterChannelsMut<'a>>
82 where
83 Self: 'a;
84
85 fn get_channel_mut(&mut self, channel: usize) -> Option<Self::ChannelMut<'_>> {
86 Some(self.buf.get_channel_mut(channel)?.skip(self.n))
87 }
88
89 fn copy_channel(&mut self, from: usize, to: usize)
90 where
91 Self::Sample: Copy,
92 {
93 self.buf.copy_channel(from, to);
94 }
95
96 fn iter_channels_mut(&mut self) -> Self::IterChannelsMut<'_> {
97 IterChannelsMut {
98 iter: self.buf.iter_channels_mut(),
99 n: self.n,
100 }
101 }
102}
103
104impl<B> ExactSizeBuf for Skip<B>
116where
117 B: ExactSizeBuf,
118{
119 fn frames(&self) -> usize {
120 self.buf.frames().saturating_sub(self.n)
121 }
122}
123
124impl<B> ReadBuf for Skip<B>
125where
126 B: ReadBuf,
127{
128 fn remaining(&self) -> usize {
129 self.buf.remaining().saturating_sub(self.n)
130 }
131
132 fn advance(&mut self, n: usize) {
133 self.buf.advance(self.n.saturating_add(n));
134 }
135}
136
137iterators!(n: usize => self.skip(n));