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, MediaKind), HandleError>
pub fn open( &mut self, path: &Path, ) -> Result<(u32, u64, MediaKind), HandleError>
Open a file, returning its handle, length, and what the host made of it.
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 insert_bytes(&mut self, bytes: Vec<u8>, kind: MediaKind) -> (u32, u64)
pub fn insert_bytes(&mut self, bytes: Vec<u8>, kind: MediaKind) -> (u32, u64)
Register bytes the host produced — a rendered page — as a new handle.
Sourcepub fn read_all(&mut self, handle: u32) -> Result<Vec<u8>, HandleError>
pub fn read_all(&mut self, handle: u32) -> Result<Vec<u8>, HandleError>
Every byte behind a handle.
Used for images headed to a vision model, where the whole thing has to be sent. Deliberately host-side only — this is the one place a whole file is materialized, and it never crosses into guest memory.
Sourcepub fn slice_bytes(
&mut self,
handle: u32,
offset: u64,
len: u64,
) -> Result<(Vec<u8>, u64), HandleError>
pub fn slice_bytes( &mut self, handle: u32, offset: u64, len: u64, ) -> Result<(Vec<u8>, u64), HandleError>
Read one window as raw bytes, with no character-boundary handling.
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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