pub struct Encoder<W: Write> { /* private fields */ }Expand description
This struct implements an encoder for the frcode format. The encoder
writes directly to the underlying Write instance.
To encode an entry you should first call write_meta a number of times
to fill the meta data portion. Then, call write_path once to finialize the entry.
One important property of this encoder is that it is safe to open and close it multiple times on the same stream, like this:
{
let encoder1 = Encoder::new(&mut stream);
} // encoder1 gets dropped here
{
let encoder2 = Encoder::new(&mut stream);
}To support this, the encoder has a “footer” item that will get written when it is dropped. This is necessary because we need to write at least one more entry to reset the shared prefix length to zero, since the next encoder will expect that as initial state.
Implementations§
Source§impl<W: Write> Encoder<W>
impl<W: Write> Encoder<W>
Sourcepub fn new(writer: W, footer_meta: Vec<u8>, footer_path: Vec<u8>) -> Encoder<W>
pub fn new(writer: W, footer_meta: Vec<u8>, footer_path: Vec<u8>) -> Encoder<W>
Constructs a new encoder for the specific writer.
The encoder will write the given footer_meta and footer_path as the last entry.
§Panics
If either footer_meta or footer_path contain NUL or newline bytes.
Sourcepub fn write_meta(&mut self, meta: &[u8]) -> Result<()>
pub fn write_meta(&mut self, meta: &[u8]) -> Result<()>
Writes the meta data of an entry to the output stream.
This function can be called multiple times to extend the current meta data part. Since the meta data is written as-is to the output stream, calling the function multiple times will concatenate the meta data of all calls.
§Panics
If the meta data contains NUL bytes or newlines.
Sourcepub fn write_path(&mut self, path: Vec<u8>) -> Result<()>
pub fn write_path(&mut self, path: Vec<u8>) -> Result<()>
Finalizes an entry by encoding its path to the output stream.
This function should be called after you’ve finished writing the meta data for the current entry. It will terminate the meta data part by writing the NUL byte and then encode the path into the output stream.
The entry will be terminated with a newline.
§Panics
If the path contains NUL bytes or newlines.
Trait Implementations§
Auto Trait Implementations§
impl<W> Freeze for Encoder<W>where
W: Freeze,
impl<W> RefUnwindSafe for Encoder<W>where
W: RefUnwindSafe,
impl<W> Send for Encoder<W>where
W: Send,
impl<W> Sync for Encoder<W>where
W: Sync,
impl<W> Unpin for Encoder<W>where
W: Unpin,
impl<W> UnsafeUnpin for Encoder<W>where
W: UnsafeUnpin,
impl<W> UnwindSafe for Encoder<W>where
W: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more