base32_fs/input.rs
1/// An input for [`decode`](crate::decode).
2pub trait Input<const N: usize> {
3 /// Get the next chunk of size `N` from the input.
4 ///
5 /// Returns `None` if the input doesn't have sufficient number of bytes.
6 fn next_chunk(&mut self) -> Option<&[u8]>;
7
8 /// Get the remainder of the input.
9 ///
10 /// Should only be called after [`next_chunk`](Self::next_chunk) returns `None`.
11 fn remainder(&self) -> &[u8];
12}
13
14impl<const N: usize> Input<N> for &[u8] {
15 fn next_chunk(&mut self) -> Option<&[u8]> {
16 let (chunk, rest) = self.split_at_checked(N)?;
17 *self = rest;
18 Some(chunk)
19 }
20
21 fn remainder(&self) -> &[u8] {
22 self
23 }
24}