pub struct ControlFile<F> { /* private fields */ }Expand description
A Plan 9-style ctl file: writing bytes invokes a caller-supplied async handler, whose result is latched and served on the next read.
Generic over the handler closure F. Construct with ControlFile::new;
the closure receives the written bytes by value (Vec<u8>, not &[u8])
and returns a boxed 'static future resolving to the response bytes, or a
MountError (rendered as-is — callers that want Wanix-style
"error: ..." text on the read side should fold that into F’s Ok arm
rather than returning Err, exactly as both TclMount/PythonMount
already do for interpreter-level errors).
Taking owned bytes (rather than &[u8]) is a deliberate API choice: a
Fn(&'a [u8]) -> DevFuture<'a, _> would need to be higher-ranked over
'a (for<'a> Fn(&'a [u8]) -> ...), which closures capturing moved
state can satisfy in principle but which the compiler frequently fails to
infer for boxed closure literals in practice (the closure’s Fn impl
collapses to one concrete lifetime instead of being universally
quantified). Owned input avoids the whole class of error and mirrors how
both existing mounts already shuttle owned String/Vec<u8> across their
command channels.
§Fid contract
Use ControlFile::new_fid in Mount::walk to create the per-open
[Fid]; call ControlFile::handle_write from Mount::write and
ControlFile::handle_read from Mount::read.
Implementations§
Source§impl<F> ControlFile<F>
impl<F> ControlFile<F>
Sourcepub fn new_fid(&self) -> DevFileState
pub fn new_fid(&self) -> DevFileState
Fresh per-fid latch state for this ctl file (nothing written yet).
Sourcepub async fn handle_write(
&self,
state: &DevFileState,
data: &[u8],
) -> Result<u32, MountError>
pub async fn handle_write( &self, state: &DevFileState, data: &[u8], ) -> Result<u32, MountError>
Handle a Mount::write: run the handler over data, latch the
result (or an "error: ..."-free propagation — the error is returned
directly, NOT latched, matching Mount::write’s Result surface) into
state, and return the byte count written on success.
Sourcepub fn handle_read(&self, state: &DevFileState, offset: u64) -> Vec<u8> ⓘ
pub fn handle_read(&self, state: &DevFileState, offset: u64) -> Vec<u8> ⓘ
Handle a Mount::read: serve the latched result (empty if nothing
has been written yet), sliced from offset.
Auto Trait Implementations§
impl<F> Freeze for ControlFile<F>where
F: Freeze,
impl<F> RefUnwindSafe for ControlFile<F>where
F: RefUnwindSafe,
impl<F> Send for ControlFile<F>where
F: Send,
impl<F> Sync for ControlFile<F>where
F: Sync,
impl<F> Unpin for ControlFile<F>where
F: Unpin,
impl<F> UnsafeUnpin for ControlFile<F>where
F: UnsafeUnpin,
impl<F> UnwindSafe for ControlFile<F>where
F: 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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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