• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use std::fmt;
2 use std::io::Write;
3 
4 /// Output buffer/writer for `CodedOutputStream`.
5 pub(crate) enum OutputTarget<'a> {
6     Write(&'a mut dyn Write, Vec<u8>),
7     Vec(&'a mut Vec<u8>),
8     /// The buffer is passed as `&[u8]` to `CodedOutputStream` constructor
9     /// and immediately converted to `buffer` field of `CodedOutputStream`,
10     /// it is not needed to be stored here.
11     /// Lifetime parameter of `CodedOutputStream` guarantees the buffer is valid
12     /// during the lifetime of `CodedOutputStream`.
13     Bytes,
14 }
15 
16 impl<'a> fmt::Debug for OutputTarget<'a> {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result17     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
18         match self {
19             OutputTarget::Write(_w, vec) => f
20                 .debug_struct("Write")
21                 .field("buf_len", &vec.len())
22                 .field("buf_cap", &vec.capacity())
23                 .finish_non_exhaustive(),
24             OutputTarget::Vec(vec) => f
25                 .debug_struct("Vec")
26                 .field("len", &vec.len())
27                 .field("cap", &vec.capacity())
28                 .finish_non_exhaustive(),
29             OutputTarget::Bytes => f.debug_tuple("Bytes").finish(),
30         }
31     }
32 }
33