base32_fs/output.rs
1/// An output of [`encode`](crate::encode) or [`decode`](crate::decode).
2///
3/// This is a simpler alternative to [`Write`](std::io::Write).
4pub trait Output {
5 /// Output one byte.
6 fn push(&mut self, ch: u8);
7}
8
9impl<T: From<u8>> Output for &mut [T] {
10 fn push(&mut self, ch: u8) {
11 // TODO split_at_mut_unchecked?
12 let (a, b) = core::mem::take(self).split_at_mut(1);
13 a[0] = ch.into();
14 *self = b;
15 }
16}
17
18#[cfg(feature = "alloc")]
19#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
20impl<T: From<u8>> Output for alloc::vec::Vec<T> {
21 fn push(&mut self, ch: u8) {
22 alloc::vec::Vec::<T>::push(self, ch.into());
23 }
24}