pub trait ResponderExt {
type Response;
const REQUEST_NAME: &'static str;
// Required method
fn send(self, response: Self::Response) -> Result<(), Error>;
// Provided methods
fn unpack_fields_or_else_send<T, F>(
self,
fields: T,
f: F,
) -> Result<(T::Unpacked, Self), Error>
where T: TryUnpack<Error = Error>,
F: FnOnce() -> Self::Response,
Self: Sized { ... }
fn unpack_fields_or_respond<T>(
self,
fields: T,
) -> Result<(T::Unpacked, Self), Error>
where T: TryUnpack<Error = Error>,
Self: ResponderExt<Response = ()> + Sized { ... }
}
Expand description
Defines an abstract ResponderExt trait usually implemented using the impl_responder_ext!() macro.
Required Associated Constants§
const REQUEST_NAME: &'static str
Required Associated Types§
Required Methods§
Provided Methods§
Sourcefn unpack_fields_or_else_send<T, F>(
self,
fields: T,
f: F,
) -> Result<(T::Unpacked, Self), Error>
fn unpack_fields_or_else_send<T, F>( self, fields: T, f: F, ) -> Result<(T::Unpacked, Self), Error>
Returns an success value containing all unpacked fields and the responder, or an error value
if any of the values in fields
is missing.
The last argument is a closure which will compute a Self::Response
. If any field is
missing a value, then this function will return an error and send the computed
Self::Response
.
Example Usage:
enum Error {
UnableToStart,
}
let ((status, id), responder) = responder.unpack_fields_or_else_send(
(payload.status.with_name("status"), payload.id.with_name("id")),
|e| (e.context(format_err!("Unable to start.")), Error::UnableToStart),
)?;
fn unpack_fields_or_respond<T>( self, fields: T, ) -> Result<(T::Unpacked, Self), Error>
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.