encode/encoders/
alloc.rs

1use crate::Encoder;
2#[cfg(feature = "alloc")]
3use alloc::vec::Vec;
4
5impl Encoder for Vec<u8> {
6    type Error = core::convert::Infallible;
7
8    fn put_slice(&mut self, slice: &[u8]) -> Result<(), Self::Error> {
9        self.extend(slice);
10        Ok(())
11    }
12
13    fn put_byte(&mut self, byte: u8) -> Result<(), Self::Error> {
14        self.push(byte);
15        Ok(())
16    }
17}
18
19#[cfg(test)]
20mod test {
21    use super::*;
22
23    #[test]
24    fn assert_that_vec_grows() {
25        let mut buf = Vec::with_capacity(1);
26        let encodable = b"hello";
27        buf.put_slice(encodable).unwrap();
28        assert_eq!(buf, b"hello", "The vector grows as necessary");
29    }
30}