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> = B::Channel<'this>
41 where
42 Self: 'this;
43
44 type IterChannels<'this> = IterChannels<B::IterChannels<'this>>
45 where
46 Self: 'this;
47
48 fn frames_hint(&self) -> Option<usize> {
49 let frames = self.buf.frames_hint()?;
50 Some(frames.saturating_sub(self.n))
51 }
52
53 fn channels(&self) -> usize {
54 self.buf.channels()
55 }
56
57 fn get_channel(&self, channel: usize) -> Option<Self::Channel<'_>> {
58 Some(self.buf.get_channel(channel)?.skip(self.n))
59 }
60
61 fn iter_channels(&self) -> Self::IterChannels<'_> {
62 IterChannels {
63 iter: self.buf.iter_channels(),
64 n: self.n,
65 }
66 }
67}
68
69impl<B> BufMut for Skip<B>
70where
71 B: BufMut,
72{
73 type ChannelMut<'a> = B::ChannelMut<'a>
74 where
75 Self: 'a;
76
77 type IterChannelsMut<'a> = IterChannelsMut<B::IterChannelsMut<'a>>
78 where
79 Self: 'a;
80
81 fn get_channel_mut(&mut self, channel: usize) -> Option<Self::ChannelMut<'_>> {
82 Some(self.buf.get_channel_mut(channel)?.skip(self.n))
83 }
84
85 fn copy_channel(&mut self, from: usize, to: usize)
86 where
87 Self::Sample: Copy,
88 {
89 self.buf.copy_channel(from, to);
90 }
91
92 fn iter_channels_mut(&mut self) -> Self::IterChannelsMut<'_> {
93 IterChannelsMut {
94 iter: self.buf.iter_channels_mut(),
95 n: self.n,
96 }
97 }
98}
99
100impl<B> ExactSizeBuf for Skip<B>
112where
113 B: ExactSizeBuf,
114{
115 fn frames(&self) -> usize {
116 self.buf.frames().saturating_sub(self.n)
117 }
118}
119
120impl<B> ReadBuf for Skip<B>
121where
122 B: ReadBuf,
123{
124 fn remaining(&self) -> usize {
125 self.buf.remaining().saturating_sub(self.n)
126 }
127
128 fn advance(&mut self, n: usize) {
129 self.buf.advance(self.n.saturating_add(n));
130 }
131}
132
133iterators!(n: usize => self.skip(n));