pub struct Handles { /* private fields */ }Expand description
A job’s open files.
Scoping this to a single job is a security property rather than tidiness.
Because the table lives and dies with one job, a handle from another job
names nothing here — which is what lets Handles::slice skip a capability
check entirely. The check happened once, at Handles::open, and a handle
cannot be forged into a reference to someone else’s data.
Implementations§
Source§impl Handles
impl Handles
Sourcepub fn open(&mut self, path: &Path) -> Result<(u32, u64), HandleError>
pub fn open(&mut self, path: &Path) -> Result<(u32, u64), HandleError>
Open a file, returning its handle and length.
The caller is responsible for having capability-checked path first —
this type deliberately knows nothing about capabilities, so that the
check lives in exactly one place rather than being half-enforced here.
Sourcepub fn slice(
&mut self,
handle: u32,
offset: u64,
len: u64,
) -> Result<Window, HandleError>
pub fn slice( &mut self, handle: u32, offset: u64, len: u64, ) -> Result<Window, HandleError>
Read one window, truncated to a UTF-8 character boundary.
The truncation is the subtle part, and the reason Window::next_offset
exists at all. A caller walking a file picks window sizes with no idea
where characters begin, so a naive read splits a multi-byte character at
nearly every seam and yields mojibake. Instead the window is cut back to
the last complete character and next_offset reports where that landed —
so a caller resuming from next_offset, rather than advancing by the
length it requested, never observes a split.
Reading past the end is not an error: the window is clamped, because a block asking for a full window at the tail of a file is behaving correctly. Starting past the end is an error, since that indicates the caller has lost track of where it is.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Handles
impl RefUnwindSafe for Handles
impl Send for Handles
impl Sync for Handles
impl Unpin for Handles
impl UnsafeUnpin for Handles
impl UnwindSafe for Handles
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> 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