#[non_exhaustive]pub struct Capabilities {
pub reads_fs: bool,
pub writes_fs: bool,
pub network: bool,
pub reads_clock: bool,
pub reads_env: bool,
pub uses_rng: bool,
pub max_steps: Option<u64>,
pub max_value_elements: Option<usize>,
}Expand description
Context-wide sandbox policy the host hands the evaluator. The per-bit
booleans are the capabilities the host grants; per-function
requirements live on NativeFnGate. A call goes through iff every
bit declared on the fn’s gate is also set here — there is no per-name
allowlist or global short-circuit, so a successful call proves that
every bit on its gate was granted.
Beyond the capability bits, this struct also carries the runtime
resource budgets (max_steps, max_value_elements) the evaluator
enforces. The analyzer’s static reachability check only reads the
capability bits and ignores the budgets, but they live on the same
struct so the evaluator’s Context keeps a single sandbox-policy
carrier (the budgets are Option<_> defaulting to “unbounded”, so a
Capabilities built purely for the analyzer is unaffected).
#[non_exhaustive]: future capability bits are added here without a
breaking semver bump. External callers should prefer constructing via
Capabilities::default / Capabilities::all_granted and mutating
fields rather than relying on field-order struct literals.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.reads_fs: boolFilesystem reads (host fn that calls std::fs::read*, also the
policy bit consulted by FilesystemModuleResolver).
writes_fs: boolFilesystem writes (host fn that calls std::fs::write* /
OpenOptions::write / create_dir* / remove_*).
network: boolNetwork access (sockets, HTTP clients, DNS).
reads_clock: boolWall / monotonic clock reads (SystemTime::now, Instant::now).
reads_env: boolProcess environment reads (std::env::var, args, etc.).
uses_rng: boolRandom number generation (any non-deterministic source).
max_steps: Option<u64>Maximum number of AST nodes to process before aborting. None
is unbounded. Consulted only by the evaluator; the analyzer
ignores it.
max_value_elements: Option<usize>Maximum number of elements in a single List or Dict. None is
unbounded. Consulted only by the evaluator; the analyzer ignores
it.
Implementations§
Source§impl Capabilities
impl Capabilities
Sourcepub fn all_granted() -> Capabilities
pub fn all_granted() -> Capabilities
Audit-visible “grant everything” preset: every capability bit
flipped, no step / value-size budget. The spec forbids an
implicit Context::trusted()-style shortcut; hosts that need
full grant must call this and read the resulting Capabilities
as data. See docs/zh/guide/spec.md §4.2.
Note: opening filesystem reads also requires installing a
non-rejecting FilesystemModuleResolver. The reads_fs flag is
the policy bit; the resolver is the machinery that enforces it.
Trait Implementations§
Source§impl CapabilityGate for Capabilities
Default gate implementation: consult the per-bit booleans on a
Capabilities snapshot.
impl CapabilityGate for Capabilities
Default gate implementation: consult the per-bit booleans on a
Capabilities snapshot.
&Capabilities is the natural carrier on the tree-walker path —
the Context already owns one. The cranelift backend constructs
its CapabilityVtable from this gate as well, so the two paths
share the exact same policy.
Source§fn check(&self, cap: CapabilityBit) -> Result<(), CapabilityBit>
fn check(&self, cap: CapabilityBit) -> Result<(), CapabilityBit>
Ok(()) if the bit is granted; Err(cap) carrying the
denied bit otherwise.Source§fn check_gate(&self, gate: &NativeFnGate) -> Result<(), CapabilityBit>
fn check_gate(&self, gate: &NativeFnGate) -> Result<(), CapabilityBit>
gate, short-circuit on the first
denial. Returns Ok(()) when the gate is fully satisfied —
the canonical “may this native fn dispatch” question. Read moreSource§impl Clone for Capabilities
impl Clone for Capabilities
Source§fn clone(&self) -> Capabilities
fn clone(&self) -> Capabilities
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Capabilities
impl Debug for Capabilities
Source§impl Default for Capabilities
impl Default for Capabilities
Source§fn default() -> Capabilities
fn default() -> Capabilities
Auto Trait Implementations§
impl Freeze for Capabilities
impl RefUnwindSafe for Capabilities
impl Send for Capabilities
impl Sync for Capabilities
impl Unpin for Capabilities
impl UnsafeUnpin for Capabilities
impl UnwindSafe for Capabilities
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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