pub enum Run<P, E>where
P: PlatformTypes,{
Unmatched(Addrd<Req<P>>),
Matched(Addrd<Message<P>>),
Error(Error<E>),
}
Expand description
A request was received and needs to be handled by Run
ning your code.
This data structure allows you to declare a re-runnable block of code that will be invoked with every incoming request.
use toad::server::ap::Hydrate;
use toad::server::{respond, Error, Run};
use toad::std::{dtls, PlatformTypes as Std};
let run: Run<Std<dtls::Y>, ()> = Run::Error(Error::Other(()));
run.maybe(|ap| {
let (_, Hydrate { req, .. }) = ap.try_unwrap_ok_hydrated().unwrap();
if req.data().path() == Ok(Some("hello")) {
let name = req.data().payload_str().unwrap_or("you nameless scoundrel");
respond::ok(format!("hi there, {}!", name).into()).hydrate(req)
} else {
respond::respond(toad::resp::code::NOT_FOUND, [].into()).hydrate(req)
}
});
Variants§
Unmatched(Addrd<Req<P>>)
Request has not been matched yet
Matched(Addrd<Message<P>>)
Request has a response
Error(Error<E>)
An Error occurred
Implementations§
source§impl<P, E> Run<P, E>where
P: PlatformTypes,
E: Debug,
impl<P, E> Run<P, E>where P: PlatformTypes, E: Debug,
Trait Implementations§
Auto Trait Implementations§
impl<P, E> RefUnwindSafe for Run<P, E>where E: RefUnwindSafe, <P as PlatformTypes>::MessageOptions: RefUnwindSafe, <P as PlatformTypes>::MessagePayload: RefUnwindSafe,
impl<P, E> Send for Run<P, E>where E: Send, <P as PlatformTypes>::MessageOptions: Send, <P as PlatformTypes>::MessagePayload: Send,
impl<P, E> Sync for Run<P, E>where E: Sync, <P as PlatformTypes>::MessageOptions: Sync, <P as PlatformTypes>::MessagePayload: Sync,
impl<P, E> Unpin for Run<P, E>where E: Unpin, <P as PlatformTypes>::MessageOptions: Unpin, <P as PlatformTypes>::MessagePayload: Unpin,
impl<P, E> UnwindSafe for Run<P, E>where E: UnwindSafe, <P as PlatformTypes>::MessageOptions: UnwindSafe, <P as PlatformTypes>::MessagePayload: 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
Mutably borrows from an owned value. Read more
source§impl<F, A, TF, T> Sequence<F, A, TF> for T
impl<F, A, TF, T> Sequence<F, A, TF> for T
source§fn sequence<Ap>(self) -> <Ap as HKT1>::T<<F as HKT1>::T<A>>where
Self: Sized + Traversable<F, <Ap as HKT1>::T<A>, A, TF> + Foldable<F, <Ap as HKT1>::T<A>>,
Ap: HKT1,
<Ap as HKT1>::T<A>: Applicative<Ap, A> + ApplyOnce<Ap, A>,
<Ap as HKT1>::T<TF>: Applicative<Ap, TF> + ApplyOnce<Ap, TF>,
<Ap as HKT1>::T<<F as HKT1>::T<A>>: Applicative<Ap, <F as HKT1>::T<A>> + ApplyOnce<Ap, <F as HKT1>::T<A>>,
F: HKT1<T<<Ap as HKT1>::T<A>> = Self>,
fn sequence<Ap>(self) -> <Ap as HKT1>::T<<F as HKT1>::T<A>>where Self: Sized + Traversable<F, <Ap as HKT1>::T<A>, A, TF> + Foldable<F, <Ap as HKT1>::T<A>>, Ap: HKT1, <Ap as HKT1>::T<A>: Applicative<Ap, A> + ApplyOnce<Ap, A>, <Ap as HKT1>::T<TF>: Applicative<Ap, TF> + ApplyOnce<Ap, TF>, <Ap as HKT1>::T<<F as HKT1>::T<A>>: Applicative<Ap, <F as HKT1>::T<A>> + ApplyOnce<Ap, <F as HKT1>::T<A>>, F: HKT1<T<<Ap as HKT1>::T<A>> = Self>,
See
Sequence