intrepid_core/action/
ready.rs

1mod ready_action;
2
3pub use ready_action::ReadyAction;
4
5/// A `Ready` type state represents an action which has a handler and a state, and can be
6/// invoked
7#[derive(Clone)]
8pub struct Ready<ActionHandler: Clone, Args: Clone, State: Clone> {
9    /// The action handler for this ready status struct.
10    pub action: ActionHandler,
11    /// The state the ready status contains.
12    pub state: State,
13    _args: std::marker::PhantomData<Args>,
14}
15
16#[tokio::test]
17async fn creating_and_resuming_statelessly() -> Result<(), tower::BoxError> {
18    use crate::Handler;
19    use tower::Service;
20
21    let action = || async {};
22    let action = action.candidate();
23
24    assert_eq!(action.stateless().call(()).await?, ().into());
25
26    Ok(())
27}
28
29#[tokio::test]
30async fn creating_and_resuming_with_state() -> Result<(), tower::BoxError> {
31    use crate::{Frame, Handler, State};
32    use tower::Service;
33
34    #[derive(Clone)]
35    struct ArbitraryState;
36
37    impl From<ArbitraryState> for Frame {
38        fn from(_: ArbitraryState) -> Self {
39            "ArbitraryState".to_owned().into()
40        }
41    }
42
43    let action = |State(state): State<ArbitraryState>| async { state };
44    let action = action.candidate();
45
46    assert_eq!(
47        action.with_state(ArbitraryState).call(()).await?,
48        "ArbitraryState".to_string().into()
49    );
50
51    Ok(())
52}