ssh_format/
ser_output.rs

1/// A trait for which can be used to store serialized output.
2pub trait SerOutput {
3    fn extend_from_slice(&mut self, other: &[u8]);
4    fn push(&mut self, byte: u8);
5
6    /// Reserves capacity for at least additional more bytes to be inserted.
7    ///
8    /// More than additional bytes may be reserved in order to avoid frequent
9    /// reallocations. A call to reserve may result in an allocation.
10    fn reserve(&mut self, additional: usize);
11}
12
13impl<T: SerOutput + ?Sized> SerOutput for &mut T {
14    fn extend_from_slice(&mut self, other: &[u8]) {
15        (*self).extend_from_slice(other)
16    }
17
18    fn push(&mut self, byte: u8) {
19        (*self).push(byte)
20    }
21
22    fn reserve(&mut self, additional: usize) {
23        (*self).reserve(additional);
24    }
25}
26
27impl SerOutput for Vec<u8> {
28    fn extend_from_slice(&mut self, other: &[u8]) {
29        self.extend_from_slice(other)
30    }
31
32    fn push(&mut self, byte: u8) {
33        self.push(byte)
34    }
35
36    fn reserve(&mut self, additional: usize) {
37        self.reserve(additional);
38    }
39}
40
41#[cfg(feature = "bytes")]
42impl SerOutput for bytes::BytesMut {
43    fn extend_from_slice(&mut self, other: &[u8]) {
44        self.extend_from_slice(other)
45    }
46
47    fn push(&mut self, byte: u8) {
48        bytes::BufMut::put_u8(self, byte)
49    }
50
51    fn reserve(&mut self, additional: usize) {
52        self.reserve(additional);
53    }
54}