pub trait Writer: Write {
type ClosureWriter: Writer + ZeroCopyWriter;
// Required methods
fn write_at<F>(&mut self, offset: usize, f: F) -> Result<usize>
where F: Fn(&mut Self::ClosureWriter) -> Result<usize>;
fn has_sufficient_buffer(&self, size: u32) -> bool;
}
Expand description
A trait for writing to the underlying FUSE endpoint. The FUSE device expects the write operation to happen in one write transaction. Since there are cases when data needs to be generated earlier than the header, it implies the writer implementation to keep an internal buffer. The buffer then can be flushed once header and data are both prepared.
Required Associated Types§
sourcetype ClosureWriter: Writer + ZeroCopyWriter
type ClosureWriter: Writer + ZeroCopyWriter
The type passed in to the closure in write_at
. For most implementations, this should be
Self
.
Required Methods§
sourcefn write_at<F>(&mut self, offset: usize, f: F) -> Result<usize>
fn write_at<F>(&mut self, offset: usize, f: F) -> Result<usize>
Allows a closure to generate and write data at the current writer’s offset. The current writer is passed as a mutable reference to the closure. As an example, this provides an adapter for the read implementation of a filesystem to write directly to the final buffer without generating the FUSE header first.
Notes: An alternative implementation would be to return a slightly different writer for the API client to write to the offset. Since the API needs to be called for more than one time, it imposes some complexity to deal with borrowing and mutability. The current approach simply does not need to create a different writer, thus no need to deal with the mentioned complexity.
sourcefn has_sufficient_buffer(&self, size: u32) -> bool
fn has_sufficient_buffer(&self, size: u32) -> bool
Checks if the writer can still accept certain amount of data.