pub struct FieldFile<G, S = NoSetter> { /* private fields */ }Expand description
A scalar field file: reading runs a caller-supplied async getter; writing
(if a setter is supplied) runs a caller-supplied async setter. Used for
vars/<name>, defs/<name>, procs/<name>-style leaves.
Unlike ControlFile, a FieldFile does not require a write before a
read — get is invoked directly on Mount::read. No per-fid latch state
is needed (constructed fresh per access), keeping it stateless and cheap
to build from a DynamicDir lookup.
S defaults to NoSetter (read-only field; FieldFile::read_only).
FieldFile::read_write takes a real setter closure. Both shapes expose
the same handle_read/handle_write methods — [NoSetter::handle_write]
always returns MountError::NotSupported, so callers don’t need to
special-case which constructor was used.
Implementations§
Source§impl<G> FieldFile<G, NoSetter>
impl<G> FieldFile<G, NoSetter>
Sourcepub fn read_only(get: G) -> Self
pub fn read_only(get: G) -> Self
Build a read-only field file. get returns None if the field no
longer exists (e.g. the variable was unset between walk and read),
surfaced as MountError::NotFound.
Source§impl<G, S> FieldFile<G, S>
impl<G, S> FieldFile<G, S>
Sourcepub fn read_write(get: G, set: S) -> Self
pub fn read_write(get: G, set: S) -> Self
Build a read/write field file.
Source§impl<G, S> FieldFile<G, S>
impl<G, S> FieldFile<G, S>
Sourcepub async fn handle_read(
&self,
offset: u64,
name: &str,
) -> Result<Vec<u8>, MountError>
pub async fn handle_read( &self, offset: u64, name: &str, ) -> Result<Vec<u8>, MountError>
Handle a Mount::read: run the getter, slice from offset.
Sourcepub async fn handle_write(&self, data: &[u8]) -> Result<u32, MountError>
pub async fn handle_write(&self, data: &[u8]) -> Result<u32, MountError>
Handle a Mount::write: run the setter (or reject, for NoSetter).
Auto Trait Implementations§
impl<G, S> Freeze for FieldFile<G, S>
impl<G, S> RefUnwindSafe for FieldFile<G, S>where
G: RefUnwindSafe,
S: RefUnwindSafe,
impl<G, S> Send for FieldFile<G, S>
impl<G, S> Sync for FieldFile<G, S>
impl<G, S> Unpin for FieldFile<G, S>
impl<G, S> UnsafeUnpin for FieldFile<G, S>where
G: UnsafeUnpin,
S: UnsafeUnpin,
impl<G, S> UnwindSafe for FieldFile<G, S>where
G: UnwindSafe,
S: 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