Trait barley_runtime::ContextAbstract
source · pub trait ContextAbstract {
// Required methods
fn add_action<'async_trait, A>(
self,
action: A
) -> Pin<Box<dyn Future<Output = Arc<dyn Action + 'static>> + Send + 'async_trait>>
where A: 'async_trait + Action + 'static,
Self: 'async_trait;
fn run<'async_trait>(
self
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait;
fn run_action<'async_trait>(
self,
action: Arc<dyn Action>
) -> Pin<Box<dyn Future<Output = Result<Option<ActionOutput>>> + Send + 'async_trait>>
where Self: 'async_trait;
fn set_variable<'life0, 'life1, 'async_trait>(
self,
name: &'life0 str,
value: &'life1 str
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn get_variable<'life0, 'async_trait>(
self,
name: &'life0 str
) -> Pin<Box<dyn Future<Output = Option<String>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn set_local<'life0, 'life1, 'life2, 'async_trait>(
self,
action: &'life0 dyn Action,
name: &'life1 str,
value: &'life2 str
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn get_local<'life0, 'life1, 'async_trait>(
self,
action: &'life0 dyn Action,
name: &'life1 str
) -> Pin<Box<dyn Future<Output = Option<String>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn get_output<'life0, 'async_trait>(
self,
action: &'life0 dyn Action
) -> Pin<Box<dyn Future<Output = Option<ActionOutput>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn get_output_arc<'async_trait>(
self,
action: Arc<dyn Action>
) -> Pin<Box<dyn Future<Output = Option<ActionOutput>> + Send + 'async_trait>>
where Self: 'async_trait;
}Expand description
The abstract interface for a context.
This should always be used in any program using
Barley, but it should never be implemented
directly. Use the barley-interface crate
instead.
Required Methods§
sourcefn add_action<'async_trait, A>(
self,
action: A
) -> Pin<Box<dyn Future<Output = Arc<dyn Action + 'static>> + Send + 'async_trait>>where
A: 'async_trait + Action + 'static,
Self: 'async_trait,
fn add_action<'async_trait, A>( self, action: A ) -> Pin<Box<dyn Future<Output = Arc<dyn Action + 'static>> + Send + 'async_trait>>where A: 'async_trait + Action + 'static, Self: 'async_trait,
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.
sourcefn run<'async_trait>(
self
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
fn run<'async_trait>( self ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where Self: 'async_trait,
Run the context.
While processing the actions, it will call the callbacks if they are set.
sourcefn run_action<'async_trait>(
self,
action: Arc<dyn Action>
) -> Pin<Box<dyn Future<Output = Result<Option<ActionOutput>>> + Send + 'async_trait>>where
Self: 'async_trait,
fn run_action<'async_trait>( self, action: Arc<dyn Action> ) -> Pin<Box<dyn Future<Output = Result<Option<ActionOutput>>> + Send + 'async_trait>>where Self: 'async_trait,
Run an individual action.
This is called internally, and should not be called directly. It is used to run individual actions, and to check if their outputs are available and successful.
sourcefn set_variable<'life0, 'life1, 'async_trait>(
self,
name: &'life0 str,
value: &'life1 str
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn set_variable<'life0, 'life1, 'async_trait>( self, name: &'life0 str, value: &'life1 str ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,
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.
sourcefn get_variable<'life0, 'async_trait>(
self,
name: &'life0 str
) -> Pin<Box<dyn Future<Output = Option<String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn get_variable<'life0, 'async_trait>( self, name: &'life0 str ) -> Pin<Box<dyn Future<Output = Option<String>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,
Gets a variable from the context.
If the variable doesn’t exist, this method
returns None.
sourcefn set_local<'life0, 'life1, 'life2, 'async_trait>(
self,
action: &'life0 dyn Action,
name: &'life1 str,
value: &'life2 str
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn set_local<'life0, 'life1, 'life2, 'async_trait>( self, action: &'life0 dyn Action, name: &'life1 str, value: &'life2 str ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,
Sets a local variable for the action.
This variable will be namespaced to the action, and will not be visible to other actions in any reasonable way. Actions could fetch the ID of the current action, and use that to access the variable, but that’s voodoo magic and you shouldn’t do it.
sourcefn get_local<'life0, 'life1, 'async_trait>(
self,
action: &'life0 dyn Action,
name: &'life1 str
) -> Pin<Box<dyn Future<Output = Option<String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get_local<'life0, 'life1, 'async_trait>( self, action: &'life0 dyn Action, name: &'life1 str ) -> Pin<Box<dyn Future<Output = Option<String>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,
Gets a local variable for the action.
This variable will be namespaced to the action, and will not be visible to other actions in any reasonable way. Actions could fetch the ID of the current action, and use that to access the variable, but that’s voodoo magic and you shouldn’t do it.
sourcefn get_output<'life0, 'async_trait>(
self,
action: &'life0 dyn Action
) -> Pin<Box<dyn Future<Output = Option<ActionOutput>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn get_output<'life0, 'async_trait>( self, action: &'life0 dyn Action ) -> Pin<Box<dyn Future<Output = Option<ActionOutput>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,
Gets the output of the action.
If the action has not been run yet, this will return
None, regardless of the action’s value after running
it. If you are using this outside of an action, you
should only use it after the context has been run.
sourcefn get_output_arc<'async_trait>(
self,
action: Arc<dyn Action>
) -> Pin<Box<dyn Future<Output = Option<ActionOutput>> + Send + 'async_trait>>where
Self: 'async_trait,
fn get_output_arc<'async_trait>( self, action: Arc<dyn Action> ) -> Pin<Box<dyn Future<Output = Option<ActionOutput>> + Send + 'async_trait>>where Self: 'async_trait,
Gets the output of an action Arc
This should be used instead of Context::get_output
if you have an Arc to the action.