Skip to main content

AccessSpec

Struct AccessSpec 

Source
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

Source

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>()));
Source

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>()));
Source

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>()));
Source

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>()));
Source

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>()));
Source

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>()));
Source

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>()));
Source

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>()));
Source

pub fn read_entries(&self) -> impl Iterator<Item = (TypeId, &'static str)> + '_

Iterates over every type this spec grants read access to, paired with its type_name for diagnostics.

§Examples
use pipeline_toolkit::AccessSpec;

struct Config;

let access = AccessSpec::new().reads::<Config>();
let entries: Vec<_> = access.read_entries().collect();
assert_eq!(entries.len(), 1);
Source

pub fn write_entries(&self) -> impl Iterator<Item = (TypeId, &'static str)> + '_

Iterates over every type this spec grants write access to, paired with its type_name for diagnostics.

§Examples
use pipeline_toolkit::AccessSpec;

struct Report;

let access = AccessSpec::new().writes::<Report>();
let entries: Vec<_> = access.write_entries().collect();
assert_eq!(entries.len(), 1);
Source

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);

Trait Implementations§

Source§

impl Clone for AccessSpec

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AccessSpec

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for AccessSpec

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.