intrepid_core/action/
active.rs

1mod active_action;
2
3use crate::ActionService;
4
5pub use active_action::ActiveAction;
6
7/// The `Active` type state represents an action which is ready to be invoked as a service.
8#[derive(Clone)]
9pub struct Active(pub ActionService);
10
11impl From<ActionService> for Active {
12    fn from(service: ActionService) -> Self {
13        Self(service)
14    }
15}
16
17#[tokio::test]
18async fn as_a_stateless_action() -> Result<(), tower::BoxError> {
19    use crate::Handler;
20
21    let action = || async {};
22    let result = action.invoke((), ()).await?;
23
24    assert_eq!(result, ().into());
25
26    Ok(())
27}
28
29#[tokio::test]
30async fn suspending_and_resuming_statelessly() -> Result<(), tower::BoxError> {
31    use crate::Handler;
32    use tower::Service;
33
34    let action = || async {};
35    let result = action.active(()).call(()).await?;
36
37    assert_eq!(result, ().into());
38
39    Ok(())
40}
41
42#[tokio::test]
43async fn as_a_stateful_service() -> Result<(), tower::BoxError> {
44    use crate::{Handler, State};
45    use tower::Service;
46
47    #[derive(Clone)]
48    struct ArbitraryState;
49
50    impl From<ArbitraryState> for crate::Frame {
51        fn from(_: ArbitraryState) -> Self {
52            "ArbitraryState".to_owned().into()
53        }
54    }
55
56    let action = |State(state): State<ArbitraryState>| async { state };
57    let result = action.active(ArbitraryState).call(()).await?;
58
59    assert_eq!(result, "ArbitraryState".to_string().into());
60
61    Ok(())
62}