Skip to main content

Module has

Module has 

Source
Expand description

The Has<P> trait — proof that a capability token includes permission P.

This is the trait you use in function signatures to declare capability requirements:

fn read_config(cap: &impl Has<FsRead>) -> String { ... }

§Multiple capabilities

Bundle permissions in a single token with a tuple:

fn sync_data(cap: &(impl Has<FsRead> + Has<NetConnect>)) { ... }

let root = test_root();
let cap = root.grant::<(FsRead, NetConnect)>();
sync_data(&cap);

Or use separate parameters:

fn sync_data(fs: &impl Has<FsRead>, net: &impl Has<NetConnect>) { ... }

Or use a subsumption type like FsAll or Ambient that satisfies multiple bounds.

§Subsumption

Cap<FsAll> satisfies Has<FsRead> and Has<FsWrite> because FsAll subsumes both. Cap<Ambient> satisfies Has<P> for every permission.

Traits§

Has
Proof that a capability token includes permission P.