Enum toad::server::Run

source ·
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 Running 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,

source

pub fn handle(ap: Ap<Complete, P, (), E>) -> Self

Lift an Ap to Run

source

pub fn maybe<F>(self, f: F) -> Selfwhere F: FnMut(Ap<Hydrated, P, (), E>) -> Ap<Complete, P, (), E>,

Use a function to potentially respond to a request

Each “maybe” branch corresponds roughly to a route / RESTful CoAP resource.

Trait Implementations§

source§

impl<P, E: Debug> Debug for Run<P, E>where P: PlatformTypes + Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<P, E> PartialEq<Run<P, E>> for Run<P, E>where P: PlatformTypes, E: PartialEq,

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

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>,

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V