Struct barley_runtime::Context

source ·
pub struct Context<'ctx> { /* private fields */ }
Expand description

A context for running actions.

There should only be one of these per workflow

Implementations§

source§

impl<'ctx> Context<'ctx>

source

pub fn new(callbacks: ContextCallbacks) -> Self

Create a new context with the given callbacks.

If you don’t want any callbacks, it’s recommended to use the Default implementation instead.

source

pub fn add_action<A: Action + 'ctx>( &mut self, action: A ) -> Arc<dyn Action + 'ctx>

Add an action to the context.

This method adds an action to the context, and returns a reference to the action. The action will be run when the context is run.

You can use the returned reference as a dependency for other actions.

source

pub async fn run(&mut self) -> Result<()>

Run the context.

While processing the actions, it will call the callbacks if they are set.

source

pub fn set_variable(&mut self, name: &str, value: &str)

Sets a variable in the context.

This can be used to send information between actions. For example, you could set a return code in one action, and check it in another.

source

pub fn get_variable(&self, name: &str) -> Option<&str>

Gets a variable from the context.

If the variable doesn’t exist, this method returns None.

Trait Implementations§

source§

impl<'ctx> Default for Context<'ctx>

source§

fn default() -> Context<'ctx>

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

Auto Trait Implementations§

§

impl<'ctx> !RefUnwindSafe for Context<'ctx>

§

impl<'ctx> Send for Context<'ctx>

§

impl<'ctx> Sync for Context<'ctx>

§

impl<'ctx> Unpin for Context<'ctx>

§

impl<'ctx> !UnwindSafe for Context<'ctx>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.