pub struct Action<ActionState: Clone> { /* private fields */ }
Expand description
The Action struct wraps an action state that describes the progression of a handler from a function-like thing into a full-blown frame service.
Implementations§
Source§impl Action<Active>
impl Action<Active>
Sourcepub fn active(service: ActionService) -> Self
pub fn active(service: ActionService) -> Self
Create an active actionable from a given action service.
Sourcepub fn into_inner(self) -> ActionService
pub fn into_inner(self) -> ActionService
Get a reference to the inner action service.
Sourcepub fn handle_frame(&mut self, frame: Frame) -> FrameFuture ⓘ
pub fn handle_frame(&mut self, frame: Frame) -> FrameFuture ⓘ
Handle a frame using an active actionable.
Sourcepub fn into_stream(self) -> (impl Stream<Item = Result<Frame>>, FrameOutbox)
pub fn into_stream(self) -> (impl Stream<Item = Result<Frame>>, FrameOutbox)
Turn the active actionable into a stream that emits frames returned by the interior service.
Take an active actionable into a stream and a stream handle. The stream handle can be used in one part of an application to send frames to the actionable wherever it is being used, and the stream will yield any frames returned from the actionable. This is useful for creating background tasks out of either the handle or the stream itself, for example to create a frame emitter out of an external event source.
In order for the stream to be consumed, it needs to be pinned first. This can be done by
calling tokio::pin!
on the stream before consuming it.
§Example
use futures::StreamExt;
use intrepid::{Action, Frame, IntoFrame, Service};
#[tokio::main]
async fn main() {
let action = |name: String| async move { format!("Hello, {}!", name).into_frame() };
let actionable = action.as_into_actionable().into_actionable(());
let (mut stream, mut handle) = actionable.into_stream();
tokio::spawn(async move {
handle.send("Alice".to_string()).await.unwrap();
handle.send("Bob".to_string()).await.unwrap();
});
tokio::pin!(stream);
while let Some(frame) = stream.next().await {
println!("{:?}", frame);
}
}
Source§impl<ActionHandler, Args, State> Action<Candidate<ActionHandler, Args, State>>
impl<ActionHandler, Args, State> Action<Candidate<ActionHandler, Args, State>>
Sourcepub fn new(action: ActionHandler) -> Self
pub fn new(action: ActionHandler) -> Self
Create an Actionable
[Candidate
] from a given ActionHandler
.
Sourcepub fn with_state(
self,
state: State,
) -> Action<Ready<ActionHandler, Args, State>>
pub fn with_state( self, state: State, ) -> Action<Ready<ActionHandler, Args, State>>
Create a new Actionable
Ready
from an action and a state.
Trait Implementations§
Source§impl<ActionHandler, Args> From<Stateless<ActionHandler, Args>> for Action<Stateless<ActionHandler, Args>>
impl<ActionHandler, Args> From<Stateless<ActionHandler, Args>> for Action<Stateless<ActionHandler, Args>>
Source§impl<ActionHandler, Args, IntoFrame> Service<IntoFrame> for Action<Stateless<ActionHandler, Args>>
impl<ActionHandler, Args, IntoFrame> Service<IntoFrame> for Action<Stateless<ActionHandler, Args>>
Auto Trait Implementations§
impl<ActionState> Freeze for Action<ActionState>where
ActionState: Freeze,
impl<ActionState> RefUnwindSafe for Action<ActionState>where
ActionState: RefUnwindSafe,
impl<ActionState> Send for Action<ActionState>where
ActionState: Send,
impl<ActionState> Sync for Action<ActionState>where
ActionState: Sync,
impl<ActionState> Unpin for Action<ActionState>where
ActionState: Unpin,
impl<ActionState> UnwindSafe for Action<ActionState>where
ActionState: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<M, S, Target, Request> MakeService<Target, Request> for M
impl<M, S, Target, Request> MakeService<Target, Request> for M
Source§fn poll_ready(
&mut self,
cx: &mut Context<'_>,
) -> Poll<Result<(), <M as MakeService<Target, Request>>::MakeError>>
fn poll_ready( &mut self, cx: &mut Context<'_>, ) -> Poll<Result<(), <M as MakeService<Target, Request>>::MakeError>>
Poll::Ready
when the factory is able to create more services. Read moreSource§fn make_service(
&mut self,
target: Target,
) -> <M as MakeService<Target, Request>>::Future
fn make_service( &mut self, target: Target, ) -> <M as MakeService<Target, Request>>::Future
Source§fn into_service(self) -> IntoService<Self, Request>where
Self: Sized,
fn into_service(self) -> IntoService<Self, Request>where
Self: Sized,
Source§fn as_service(&mut self) -> AsService<'_, Self, Request>where
Self: Sized,
fn as_service(&mut self) -> AsService<'_, Self, Request>where
Self: Sized,
Source§impl<S, R> ServiceExt<R> for Swhere
S: Service<R>,
impl<S, R> ServiceExt<R> for Swhere
S: Service<R>,
Source§fn into_make_service(self) -> IntoMakeService<S>
fn into_make_service(self) -> IntoMakeService<S>
MakeService
, that is a Service
whose
response is another service. Read moreSource§fn into_make_service_with_connect_info<C>(
self,
) -> IntoMakeServiceWithConnectInfo<S, C>
fn into_make_service_with_connect_info<C>( self, ) -> IntoMakeServiceWithConnectInfo<S, C>
MakeService
, that will store C
’s
associated ConnectInfo
in a request extension such that ConnectInfo
can extract it. Read moreSource§fn handle_error<F, T>(self, f: F) -> HandleError<Self, F, T>
fn handle_error<F, T>(self, f: F) -> HandleError<Self, F, T>
HandleError
, that will handle errors
by converting them into responses. Read moreSource§impl<T, Request> ServiceExt<Request> for T
impl<T, Request> ServiceExt<Request> for T
Source§fn ready(&mut self) -> Ready<'_, Self, Request>where
Self: Sized,
fn ready(&mut self) -> Ready<'_, Self, Request>where
Self: Sized,
Source§fn ready_and(&mut self) -> Ready<'_, Self, Request>where
Self: Sized,
fn ready_and(&mut self) -> Ready<'_, Self, Request>where
Self: Sized,
ServiceExt::ready
method insteadSource§fn ready_oneshot(self) -> ReadyOneshot<Self, Request>where
Self: Sized,
fn ready_oneshot(self) -> ReadyOneshot<Self, Request>where
Self: Sized,
Source§fn oneshot(self, req: Request) -> Oneshot<Self, Request>where
Self: Sized,
fn oneshot(self, req: Request) -> Oneshot<Self, Request>where
Self: Sized,
Service
, calling with the providing request once it is ready.Source§fn and_then<F>(self, f: F) -> AndThen<Self, F>
fn and_then<F>(self, f: F) -> AndThen<Self, F>
poll_ready
method. Read moreSource§fn map_response<F, Response>(self, f: F) -> MapResponse<Self, F>
fn map_response<F, Response>(self, f: F) -> MapResponse<Self, F>
poll_ready
method. Read moreSource§fn map_err<F, Error>(self, f: F) -> MapErr<Self, F>
fn map_err<F, Error>(self, f: F) -> MapErr<Self, F>
poll_ready
method. Read moreSource§fn map_result<F, Response, Error>(self, f: F) -> MapResult<Self, F>
fn map_result<F, Response, Error>(self, f: F) -> MapResult<Self, F>
Result<Self::Response, Self::Error>
)
to a different value, regardless of whether the future succeeds or
fails. Read moreSource§fn map_request<F, NewRequest>(self, f: F) -> MapRequest<Self, F>
fn map_request<F, NewRequest>(self, f: F) -> MapRequest<Self, F>
Source§fn filter_async<F, NewRequest>(self, filter: F) -> AsyncFilter<Self, F>where
Self: Sized,
F: AsyncPredicate<NewRequest>,
fn filter_async<F, NewRequest>(self, filter: F) -> AsyncFilter<Self, F>where
Self: Sized,
F: AsyncPredicate<NewRequest>,
AsyncFilter
that conditionally accepts or
rejects requests based on an [async predicate]. Read moreSource§fn then<F, Response, Error, Fut>(self, f: F) -> Then<Self, F>
fn then<F, Response, Error, Fut>(self, f: F) -> Then<Self, F>
Source§fn map_future<F, Fut, Response, Error>(self, f: F) -> MapFuture<Self, F>
fn map_future<F, Fut, Response, Error>(self, f: F) -> MapFuture<Self, F>
Source§impl<T, Request> ServiceExt<Request> for T
impl<T, Request> ServiceExt<Request> for T
Source§fn ready(&mut self) -> Ready<'_, Self, Request>where
Self: Sized,
fn ready(&mut self) -> Ready<'_, Self, Request>where
Self: Sized,
Source§fn ready_oneshot(self) -> ReadyOneshot<Self, Request>where
Self: Sized,
fn ready_oneshot(self) -> ReadyOneshot<Self, Request>where
Self: Sized,
Source§fn oneshot(self, req: Request) -> Oneshot<Self, Request>where
Self: Sized,
fn oneshot(self, req: Request) -> Oneshot<Self, Request>where
Self: Sized,
Service
, calling it with the provided request once it is ready.Source§fn and_then<F>(self, f: F) -> AndThen<Self, F>
fn and_then<F>(self, f: F) -> AndThen<Self, F>
poll_ready
method. Read moreSource§fn map_response<F, Response>(self, f: F) -> MapResponse<Self, F>
fn map_response<F, Response>(self, f: F) -> MapResponse<Self, F>
poll_ready
method. Read moreSource§fn map_err<F, Error>(self, f: F) -> MapErr<Self, F>
fn map_err<F, Error>(self, f: F) -> MapErr<Self, F>
poll_ready
method. Read moreSource§fn map_result<F, Response, Error>(self, f: F) -> MapResult<Self, F>
fn map_result<F, Response, Error>(self, f: F) -> MapResult<Self, F>
Result<Self::Response, Self::Error>
)
to a different value, regardless of whether the future succeeds or
fails. Read more