Struct breadboard::Breadboard
source · pub struct Breadboard { /* private fields */ }
Expand description
A router builder.
Register your routes, then use hyper’s NewService
trait to create the service.
See the crate-level documentation for examples.
Anatomy of a handler
A handler is a function that takes a single argument, Request<T>
. T
must implement
serde::Deserialize
.
The handler returns a type that implements IntoFuture
. The future’s Item
is a
Response<T>
, where T
must implement serde::Serialize
. The future’s
Error
can be anything that implements std::error::Error
, Send
, and
Sync
.
If you aren’t doing any work in your handler that requires use of futures, you can simply
return a Result
, as Result
implements IntoFuture
.
Implementations§
source§impl Breadboard
impl Breadboard
sourcepub fn route<A, F, R, D, S, E>(self, method: Method, route: A, handler: F) -> Selfwhere
A: AsRef<str>,
F: Fn(Request<D>) -> R + Send + Sync + 'static,
R: IntoFuture<Item = Response<S>, Error = E> + 'static,
R::Future: Send,
for<'de> D: Deserialize<'de> + Send + 'static,
S: Serialize + 'static,
E: Into<Box<dyn Error + Send + Sync>>,
pub fn route<A, F, R, D, S, E>(self, method: Method, route: A, handler: F) -> Selfwhere
A: AsRef<str>,
F: Fn(Request<D>) -> R + Send + Sync + 'static,
R: IntoFuture<Item = Response<S>, Error = E> + 'static,
R::Future: Send,
for<'de> D: Deserialize<'de> + Send + 'static,
S: Serialize + 'static,
E: Into<Box<dyn Error + Send + Sync>>,
Add a handler for a route with the given method.
sourcepub fn get<A, F, R, D, S, E>(self, route: A, handler: F) -> Selfwhere
A: AsRef<str>,
F: Fn(Request<D>) -> R + Send + Sync + 'static,
R: IntoFuture<Item = Response<S>, Error = E> + 'static,
R::Future: Send,
for<'de> D: Deserialize<'de> + Send + 'static,
S: Serialize + 'static,
E: Into<Box<dyn Error + Send + Sync>>,
pub fn get<A, F, R, D, S, E>(self, route: A, handler: F) -> Selfwhere
A: AsRef<str>,
F: Fn(Request<D>) -> R + Send + Sync + 'static,
R: IntoFuture<Item = Response<S>, Error = E> + 'static,
R::Future: Send,
for<'de> D: Deserialize<'de> + Send + 'static,
S: Serialize + 'static,
E: Into<Box<dyn Error + Send + Sync>>,
Add a handler for GET requests for a route.
sourcepub fn post<A, F, R, D, S, E>(self, route: A, handler: F) -> Selfwhere
A: AsRef<str>,
F: Fn(Request<D>) -> R + Send + Sync + 'static,
R: IntoFuture<Item = Response<S>, Error = E> + 'static,
R::Future: Send,
for<'de> D: Deserialize<'de> + Send + 'static,
S: Serialize + 'static,
E: Into<Box<dyn Error + Send + Sync>>,
pub fn post<A, F, R, D, S, E>(self, route: A, handler: F) -> Selfwhere
A: AsRef<str>,
F: Fn(Request<D>) -> R + Send + Sync + 'static,
R: IntoFuture<Item = Response<S>, Error = E> + 'static,
R::Future: Send,
for<'de> D: Deserialize<'de> + Send + 'static,
S: Serialize + 'static,
E: Into<Box<dyn Error + Send + Sync>>,
Add a handler for POST requests for a route.
sourcepub fn put<A, F, R, D, S, E>(self, route: A, handler: F) -> Selfwhere
A: AsRef<str>,
F: Fn(Request<D>) -> R + Send + Sync + 'static,
R: IntoFuture<Item = Response<S>, Error = E> + 'static,
R::Future: Send,
for<'de> D: Deserialize<'de> + Send + 'static,
S: Serialize + 'static,
E: Into<Box<dyn Error + Send + Sync>>,
pub fn put<A, F, R, D, S, E>(self, route: A, handler: F) -> Selfwhere
A: AsRef<str>,
F: Fn(Request<D>) -> R + Send + Sync + 'static,
R: IntoFuture<Item = Response<S>, Error = E> + 'static,
R::Future: Send,
for<'de> D: Deserialize<'de> + Send + 'static,
S: Serialize + 'static,
E: Into<Box<dyn Error + Send + Sync>>,
Add a handler for PUT requests for a route.
sourcepub fn delete<A, F, R, D, S, E>(self, route: A, handler: F) -> Selfwhere
A: AsRef<str>,
F: Fn(Request<D>) -> R + Send + Sync + 'static,
R: IntoFuture<Item = Response<S>, Error = E> + 'static,
R::Future: Send,
for<'de> D: Deserialize<'de> + Send + 'static,
S: Serialize + 'static,
E: Into<Box<dyn Error + Send + Sync>>,
pub fn delete<A, F, R, D, S, E>(self, route: A, handler: F) -> Selfwhere
A: AsRef<str>,
F: Fn(Request<D>) -> R + Send + Sync + 'static,
R: IntoFuture<Item = Response<S>, Error = E> + 'static,
R::Future: Send,
for<'de> D: Deserialize<'de> + Send + 'static,
S: Serialize + 'static,
E: Into<Box<dyn Error + Send + Sync>>,
Add a handler for DELETE requests for a route.
sourcepub fn head<A, F, R, D, S, E>(self, route: A, handler: F) -> Selfwhere
A: AsRef<str>,
F: Fn(Request<D>) -> R + Send + Sync + 'static,
R: IntoFuture<Item = Response<S>, Error = E> + 'static,
R::Future: Send,
for<'de> D: Deserialize<'de> + Send + 'static,
S: Serialize + 'static,
E: Into<Box<dyn Error + Send + Sync>>,
pub fn head<A, F, R, D, S, E>(self, route: A, handler: F) -> Selfwhere
A: AsRef<str>,
F: Fn(Request<D>) -> R + Send + Sync + 'static,
R: IntoFuture<Item = Response<S>, Error = E> + 'static,
R::Future: Send,
for<'de> D: Deserialize<'de> + Send + 'static,
S: Serialize + 'static,
E: Into<Box<dyn Error + Send + Sync>>,
Add a handler for HEAD requests for a route.
sourcepub fn options<A, F, R, D, S, E>(self, route: A, handler: F) -> Selfwhere
A: AsRef<str>,
F: Fn(Request<D>) -> R + Send + Sync + 'static,
R: IntoFuture<Item = Response<S>, Error = E> + 'static,
R::Future: Send,
for<'de> D: Deserialize<'de> + Send + 'static,
S: Serialize + 'static,
E: Into<Box<dyn Error + Send + Sync>>,
pub fn options<A, F, R, D, S, E>(self, route: A, handler: F) -> Selfwhere
A: AsRef<str>,
F: Fn(Request<D>) -> R + Send + Sync + 'static,
R: IntoFuture<Item = Response<S>, Error = E> + 'static,
R::Future: Send,
for<'de> D: Deserialize<'de> + Send + 'static,
S: Serialize + 'static,
E: Into<Box<dyn Error + Send + Sync>>,
Add a handler for OPTIONS requests for a route.
sourcepub fn connect<A, F, R, D, S, E>(self, route: A, handler: F) -> Selfwhere
A: AsRef<str>,
F: Fn(Request<D>) -> R + Send + Sync + 'static,
R: IntoFuture<Item = Response<S>, Error = E> + 'static,
R::Future: Send,
for<'de> D: Deserialize<'de> + Send + 'static,
S: Serialize + 'static,
E: Into<Box<dyn Error + Send + Sync>>,
pub fn connect<A, F, R, D, S, E>(self, route: A, handler: F) -> Selfwhere
A: AsRef<str>,
F: Fn(Request<D>) -> R + Send + Sync + 'static,
R: IntoFuture<Item = Response<S>, Error = E> + 'static,
R::Future: Send,
for<'de> D: Deserialize<'de> + Send + 'static,
S: Serialize + 'static,
E: Into<Box<dyn Error + Send + Sync>>,
Add a handler for CONNECT requests for a route.
sourcepub fn patch<A, F, R, D, S, E>(self, route: A, handler: F) -> Selfwhere
A: AsRef<str>,
F: Fn(Request<D>) -> R + Send + Sync + 'static,
R: IntoFuture<Item = Response<S>, Error = E> + 'static,
R::Future: Send,
for<'de> D: Deserialize<'de> + Send + 'static,
S: Serialize + 'static,
E: Into<Box<dyn Error + Send + Sync>>,
pub fn patch<A, F, R, D, S, E>(self, route: A, handler: F) -> Selfwhere
A: AsRef<str>,
F: Fn(Request<D>) -> R + Send + Sync + 'static,
R: IntoFuture<Item = Response<S>, Error = E> + 'static,
R::Future: Send,
for<'de> D: Deserialize<'de> + Send + 'static,
S: Serialize + 'static,
E: Into<Box<dyn Error + Send + Sync>>,
Add a handler for PATCH requests for a route.
sourcepub fn trace<A, F, R, D, S, E>(self, route: A, handler: F) -> Selfwhere
A: AsRef<str>,
F: Fn(Request<D>) -> R + Send + Sync + 'static,
R: IntoFuture<Item = Response<S>, Error = E> + 'static,
R::Future: Send,
for<'de> D: Deserialize<'de> + Send + 'static,
S: Serialize + 'static,
E: Into<Box<dyn Error + Send + Sync>>,
pub fn trace<A, F, R, D, S, E>(self, route: A, handler: F) -> Selfwhere
A: AsRef<str>,
F: Fn(Request<D>) -> R + Send + Sync + 'static,
R: IntoFuture<Item = Response<S>, Error = E> + 'static,
R::Future: Send,
for<'de> D: Deserialize<'de> + Send + 'static,
S: Serialize + 'static,
E: Into<Box<dyn Error + Send + Sync>>,
Add a handler for TRACE requests for a route.
sourcepub fn build(&self) -> Result<Service, BuildError>
pub fn build(&self) -> Result<Service, BuildError>
fixme
Trait Implementations§
source§impl Debug for Breadboard
impl Debug for Breadboard
source§impl Default for Breadboard
impl Default for Breadboard
source§fn default() -> Breadboard
fn default() -> Breadboard
source§impl NewService for Breadboard
impl NewService for Breadboard
§type Error = RequestError
type Error = RequestError
Service
s.§type Future = FutureResult<Service, BuildError>
type Future = FutureResult<Service, BuildError>
new_service
of a Service
.§type InitError = BuildError
type InitError = BuildError
Service
.source§fn new_service(&self) -> Self::Future
fn new_service(&self) -> Self::Future
Service
.Auto Trait Implementations§
impl !RefUnwindSafe for Breadboard
impl Send for Breadboard
impl Sync for Breadboard
impl Unpin for Breadboard
impl !UnwindSafe for Breadboard
Blanket Implementations§
source§impl<N, Ctx> MakeService<Ctx> for Nwhere
N: NewService,
impl<N, Ctx> MakeService<Ctx> for Nwhere
N: NewService,
§type ReqBody = <N as NewService>::ReqBody
type ReqBody = <N as NewService>::ReqBody
Payload
body of the http::Request
.§type ResBody = <N as NewService>::ResBody
type ResBody = <N as NewService>::ResBody
Payload
body of the http::Response
.§type Error = <N as NewService>::Error
type Error = <N as NewService>::Error
Service
s.§type Service = <N as NewService>::Service
type Service = <N as NewService>::Service
Service
from new_service()
.§type Future = <N as NewService>::Future
type Future = <N as NewService>::Future
new_service
of a Service
.§type MakeError = <N as NewService>::InitError
type MakeError = <N as NewService>::InitError
Service
.source§fn poll_ready(
&mut self
) -> Result<Async<()>, <N as MakeService<Ctx>>::MakeError>
fn poll_ready(
&mut self
) -> Result<Async<()>, <N as MakeService<Ctx>>::MakeError>
source§fn make_service(&mut self, _: Ctx) -> <N as MakeService<Ctx>>::Future
fn make_service(&mut self, _: Ctx) -> <N as MakeService<Ctx>>::Future
Service
.