pub struct AccessSpec { /* private fields */ }Expand description
The set of Context entry types a Step is allowed to
read, write, or consume, keyed by TypeId.
A step returns its AccessSpec from
Step::access.
PipelineBuilder::build uses it
statically, to check that every declared read is satisfied by an earlier
step’s declared write (or the pipeline input), and Context uses it
dynamically, at run time, to reject reads, writes, and Context::take
calls the step didn’t declare.
§Examples
use pipeline_toolkit::AccessSpec;
use std::any::TypeId;
struct Config;
struct Report;
let access = AccessSpec::new().reads::<Config>().writes::<Report>();
assert!(access.can_read(TypeId::of::<Config>()));
assert!(access.can_write(TypeId::of::<Report>()));
assert!(!access.can_write(TypeId::of::<Config>()));Implementations§
Source§impl AccessSpec
impl AccessSpec
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty spec that grants no access.
§Examples
use pipeline_toolkit::AccessSpec;
use std::any::TypeId;
struct Config;
let access = AccessSpec::new();
assert!(!access.can_read(TypeId::of::<Config>()));Sourcepub fn reads<T: 'static>(self) -> Self
pub fn reads<T: 'static>(self) -> Self
Grants read access to T.
§Examples
use pipeline_toolkit::AccessSpec;
use std::any::TypeId;
struct Config;
let access = AccessSpec::new().reads::<Config>();
assert!(access.can_read(TypeId::of::<Config>()));
assert!(!access.can_write(TypeId::of::<Config>()));Sourcepub fn writes<T: 'static>(self) -> Self
pub fn writes<T: 'static>(self) -> Self
Grants write access to T.
§Examples
use pipeline_toolkit::AccessSpec;
use std::any::TypeId;
struct Report;
let access = AccessSpec::new().writes::<Report>();
assert!(access.can_write(TypeId::of::<Report>()));
assert!(!access.can_read(TypeId::of::<Report>()));Sourcepub fn reads_writes<T: 'static>(self) -> Self
pub fn reads_writes<T: 'static>(self) -> Self
Grants both read and write access to T, for a step that mutates a
value in place via Context::get_mut rather than replacing it.
Unlike Self::consumes, this leaves T marked as written for
PipelineBuilder::build’s
purposes, so a downstream step can still declare a read of it.
§Examples
use pipeline_toolkit::AccessSpec;
use std::any::TypeId;
struct Counter;
let access = AccessSpec::new().reads_writes::<Counter>();
assert!(access.can_read(TypeId::of::<Counter>()));
assert!(access.can_write(TypeId::of::<Counter>()));Sourcepub fn consumes<T: 'static>(self) -> Self
pub fn consumes<T: 'static>(self) -> Self
Declares that this step will call Context::take for T, removing
it from the context. Implies read and write access. Unlike
Self::reads_writes (used for in-place mutation via
Context::get_mut, which leaves the value in place),
PipelineBuilder::build treats a
consumed type as no longer written once this step runs, so a
downstream step reading it without an intervening write is caught at
build time instead of silently seeing None at runtime.
§Examples
use pipeline_toolkit::AccessSpec;
use std::any::TypeId;
struct Payload;
let access = AccessSpec::new().consumes::<Payload>();
assert!(access.can_read(TypeId::of::<Payload>()));
assert!(access.can_write(TypeId::of::<Payload>()));
assert!(access.can_consume(TypeId::of::<Payload>()));Sourcepub fn can_read(&self, id: TypeId) -> bool
pub fn can_read(&self, id: TypeId) -> bool
Reports whether this spec grants read access to the type identified
by id.
§Examples
use pipeline_toolkit::AccessSpec;
use std::any::TypeId;
struct Config;
let access = AccessSpec::new().reads::<Config>();
assert!(access.can_read(TypeId::of::<Config>()));Sourcepub fn can_write(&self, id: TypeId) -> bool
pub fn can_write(&self, id: TypeId) -> bool
Reports whether this spec grants write access to the type identified
by id.
§Examples
use pipeline_toolkit::AccessSpec;
use std::any::TypeId;
struct Report;
let access = AccessSpec::new().writes::<Report>();
assert!(access.can_write(TypeId::of::<Report>()));Sourcepub fn can_consume(&self, id: TypeId) -> bool
pub fn can_consume(&self, id: TypeId) -> bool
Reports whether this spec grants Context::take access to the type
identified by id.
§Examples
use pipeline_toolkit::AccessSpec;
use std::any::TypeId;
struct Payload;
let access = AccessSpec::new().consumes::<Payload>();
assert!(access.can_consume(TypeId::of::<Payload>()));Sourcepub fn read_entries(&self) -> impl Iterator<Item = (TypeId, &'static str)> + '_
pub fn read_entries(&self) -> impl Iterator<Item = (TypeId, &'static str)> + '_
Sourcepub fn write_entries(&self) -> impl Iterator<Item = (TypeId, &'static str)> + '_
pub fn write_entries(&self) -> impl Iterator<Item = (TypeId, &'static str)> + '_
Sourcepub fn consume_entries(
&self,
) -> impl Iterator<Item = (TypeId, &'static str)> + '_
pub fn consume_entries( &self, ) -> impl Iterator<Item = (TypeId, &'static str)> + '_
Iterates over every type this spec grants Context::take access
to, paired with its type_name for diagnostics.
§Examples
use pipeline_toolkit::AccessSpec;
struct Payload;
let access = AccessSpec::new().consumes::<Payload>();
let entries: Vec<_> = access.consume_entries().collect();
assert_eq!(entries.len(), 1);