Struct axum::Router [−][src]
pub struct Router<S> { /* fields omitted */ }
Expand description
The router type for composing handlers and services.
Implementations
Add another route to the router.
description
is a string of path segments separated by /
. Each segment
can be either concrete or a capture:
/foo/bar/baz
will only match requests where the path is/foo/bar/bar
./:foo
will match any route with exactly one segment and it will capture the first segment and store it at the keyfoo
.
service
is the Service
that should receive the request if the path
matches description
.
Example
use axum::{handler::{get, delete}, Router};
let app = Router::new()
.route("/", get(root))
.route("/users", get(list_users).post(create_user))
.route("/users/:id", get(show_user))
.route("/api/:version/users/:id/action", delete(do_thing));
async fn root() { /* ... */ }
async fn list_users() { /* ... */ }
async fn create_user() { /* ... */ }
async fn show_user() { /* ... */ }
async fn do_thing() { /* ... */ }
Panics
Panics if description
doesn’t start with /
.
Nest a group of routes (or a Service
) at some path.
This allows you to break your application into smaller pieces and compose them together.
use axum::{
handler::get,
Router,
};
use http::Uri;
async fn users_get(uri: Uri) {
// `uri` will be `/users` since `nest` strips the matching prefix.
// use `OriginalUri` to always get the full URI.
}
async fn users_post() {}
async fn careers() {}
let users_api = Router::new().route("/users", get(users_get).post(users_post));
let app = Router::new()
.nest("/api", users_api)
.route("/careers", get(careers));
Note that nested routes will not see the orignal request URI but instead
have the matched prefix stripped. This is necessary for services like static
file serving to work. Use OriginalUri
if you need the original request
URI.
Take care when using nest
together with dynamic routes as nesting also
captures from the outer routes:
use axum::{
extract::Path,
handler::get,
Router,
};
use std::collections::HashMap;
async fn users_get(Path(params): Path<HashMap<String, String>>) {
// Both `version` and `id` were captured even though `users_api` only
// explicitly captures `id`.
let version = params.get("version");
let id = params.get("id");
}
let users_api = Router::new().route("/users/:id", get(users_get));
let app = Router::new().nest("/:version/api", users_api);
nest
also accepts any Service
. This can for example be used with
tower_http::services::ServeDir
to serve static files from a directory:
use axum::{
Router,
service::get,
};
use tower_http::services::ServeDir;
// Serves files inside the `public` directory at `GET /public/*`
let serve_dir_service = ServeDir::new("public");
let app = Router::new().nest("/public", get(serve_dir_service));
If necessary you can use Router::boxed
to box a group of routes
making the type easier to name. This is sometimes useful when working with
nest
.
pub fn boxed<ReqBody, ResBody>(self) -> Router<BoxRoute<ReqBody, S::Error>> where
S: Service<Request<ReqBody>, Response = Response<ResBody>> + Send + 'static,
S::Error: Into<BoxError> + Send + Sync,
S::Future: Send,
ReqBody: Body<Data = Bytes> + Send + Sync + 'static,
ReqBody::Error: Into<BoxError> + Send + Sync + 'static,
ResBody: Body<Data = Bytes> + Send + Sync + 'static,
ResBody::Error: Into<BoxError> + Send + Sync + 'static,
pub fn boxed<ReqBody, ResBody>(self) -> Router<BoxRoute<ReqBody, S::Error>> where
S: Service<Request<ReqBody>, Response = Response<ResBody>> + Send + 'static,
S::Error: Into<BoxError> + Send + Sync,
S::Future: Send,
ReqBody: Body<Data = Bytes> + Send + Sync + 'static,
ReqBody::Error: Into<BoxError> + Send + Sync + 'static,
ResBody: Body<Data = Bytes> + Send + Sync + 'static,
ResBody::Error: Into<BoxError> + Send + Sync + 'static,
Create a boxed route trait object.
This makes it easier to name the types of routers to, for example, return them from functions:
use axum::{
body::Body,
handler::get,
Router,
routing::BoxRoute
};
async fn first_handler() { /* ... */ }
async fn second_handler() { /* ... */ }
async fn third_handler() { /* ... */ }
fn app() -> Router<BoxRoute> {
Router::new()
.route("/", get(first_handler).post(second_handler))
.route("/foo", get(third_handler))
.boxed()
}
It also helps with compile times when you have a very large number of routes.
Apply a tower::Layer
to the router.
All requests to the router will be processed by the layer’s corresponding middleware.
This can be used to add additional processing to a request for a group of routes.
Note this differs from handler::Layered
which adds a middleware to a single handler.
Example
Adding the tower::limit::ConcurrencyLimit
middleware to a group of
routes can be done like so:
use axum::{
handler::get,
Router,
};
use tower::limit::{ConcurrencyLimitLayer, ConcurrencyLimit};
async fn first_handler() { /* ... */ }
async fn second_handler() { /* ... */ }
async fn third_handler() { /* ... */ }
// All requests to `handler` and `other_handler` will be sent through
// `ConcurrencyLimit`
let app = Router::new().route("/", get(first_handler))
.route("/foo", get(second_handler))
.layer(ConcurrencyLimitLayer::new(64))
// Request to `GET /bar` will go directly to `third_handler` and
// wont be sent through `ConcurrencyLimit`
.route("/bar", get(third_handler));
This is commonly used to add middleware such as tracing/logging to your entire app:
use axum::{
handler::get,
Router,
};
use tower_http::trace::TraceLayer;
async fn first_handler() { /* ... */ }
async fn second_handler() { /* ... */ }
async fn third_handler() { /* ... */ }
let app = Router::new()
.route("/", get(first_handler))
.route("/foo", get(second_handler))
.route("/bar", get(third_handler))
.layer(TraceLayer::new_for_http());
Convert this router into a MakeService
, that is a Service
who’s
response is another service.
This is useful when running your application with hyper’s
Server
:
use axum::{
handler::get,
Router,
};
let app = Router::new().route("/", get(|| async { "Hi!" }));
axum::Server::bind(&"0.0.0.0:3000".parse().unwrap())
.serve(app.into_make_service())
.await
.expect("server failed");
pub fn into_make_service_with_connect_info<C, Target>(
self
) -> IntoMakeServiceWithConnectInfo<S, C> where
S: Clone,
C: Connected<Target>,
pub fn into_make_service_with_connect_info<C, Target>(
self
) -> IntoMakeServiceWithConnectInfo<S, C> where
S: Clone,
C: Connected<Target>,
Convert this router into a MakeService
, that will store C
’s
associated ConnectInfo
in a request extension such that ConnectInfo
can extract it.
This enables extracting things like the client’s remote address.
Extracting std::net::SocketAddr
is supported out of the box:
use axum::{
extract::ConnectInfo,
handler::get,
Router,
};
use std::net::SocketAddr;
let app = Router::new().route("/", get(handler));
async fn handler(ConnectInfo(addr): ConnectInfo<SocketAddr>) -> String {
format!("Hello {}", addr)
}
axum::Server::bind(&"0.0.0.0:3000".parse().unwrap())
.serve(
app.into_make_service_with_connect_info::<SocketAddr, _>()
)
.await
.expect("server failed");
You can implement custom a Connected
like so:
use axum::{
extract::connect_info::{ConnectInfo, Connected},
handler::get,
Router,
};
use hyper::server::conn::AddrStream;
let app = Router::new().route("/", get(handler));
async fn handler(
ConnectInfo(my_connect_info): ConnectInfo<MyConnectInfo>,
) -> String {
format!("Hello {:?}", my_connect_info)
}
#[derive(Clone, Debug)]
struct MyConnectInfo {
// ...
}
impl Connected<&AddrStream> for MyConnectInfo {
type ConnectInfo = MyConnectInfo;
fn connect_info(target: &AddrStream) -> Self::ConnectInfo {
MyConnectInfo {
// ...
}
}
}
axum::Server::bind(&"0.0.0.0:3000".parse().unwrap())
.serve(
app.into_make_service_with_connect_info::<MyConnectInfo, _>()
)
.await
.expect("server failed");
See the unix domain socket example for an example of how to use this to collect UDS connection info.
Merge two routers into one.
This is useful for breaking apps into smaller pieces and combining them into one.
use axum::{
handler::get,
Router,
};
// define some routes separately
let user_routes = Router::new()
.route("/users", get(users_list))
.route("/users/:id", get(users_show));
let team_routes = Router::new().route("/teams", get(teams_list));
// combine them into one
let app = user_routes.or(team_routes);
Handle errors services in this router might produce, by mapping them to responses.
Unhandled errors will close the connection without sending a response.
Example
use axum::{
handler::get,
http::StatusCode,
Router,
};
use tower::{BoxError, timeout::TimeoutLayer};
use std::{time::Duration, convert::Infallible};
// This router can never fail, since handlers can never fail.
let app = Router::new().route("/", get(|| async {}));
// Now the router can fail since the `tower::timeout::Timeout`
// middleware will return an error if the timeout elapses.
let app = app.layer(TimeoutLayer::new(Duration::from_secs(10)));
// With `handle_error` we can handle errors `Timeout` might produce.
// Our router now cannot fail, that is its error type is `Infallible`.
let app = app.handle_error(|error: BoxError| {
if error.is::<tower::timeout::error::Elapsed>() {
Ok::<_, Infallible>((
StatusCode::REQUEST_TIMEOUT,
"request took too long to handle".to_string(),
))
} else {
Ok::<_, Infallible>((
StatusCode::INTERNAL_SERVER_ERROR,
format!("Unhandled error: {}", error),
))
}
});
You can return Err(_)
from the closure if you don’t wish to handle
some errors:
use axum::{
handler::get,
http::StatusCode,
Router,
};
use tower::{BoxError, timeout::TimeoutLayer};
use std::time::Duration;
let app = Router::new()
.route("/", get(|| async {}))
.layer(TimeoutLayer::new(Duration::from_secs(10)))
.handle_error(|error: BoxError| {
if error.is::<tower::timeout::error::Elapsed>() {
Ok((
StatusCode::REQUEST_TIMEOUT,
"request took too long to handle".to_string(),
))
} else {
// return the error as is
Err(error)
}
});
Check that your service cannot fail.
That is, its error type is Infallible
.
Trait Implementations
Auto Trait Implementations
impl<S> RefUnwindSafe for Router<S> where
S: RefUnwindSafe,
impl<S> UnwindSafe for Router<S> where
S: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
fn fmt_binary(self) -> FmtBinary<Self> where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self> where
Self: Binary,
Causes self
to use its Binary
implementation when Debug
-formatted.
fn fmt_display(self) -> FmtDisplay<Self> where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self> where
Self: Display,
Causes self
to use its Display
implementation when
Debug
-formatted. Read more
fn fmt_lower_exp(self) -> FmtLowerExp<Self> where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self> where
Self: LowerExp,
Causes self
to use its LowerExp
implementation when
Debug
-formatted. Read more
fn fmt_lower_hex(self) -> FmtLowerHex<Self> where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self> where
Self: LowerHex,
Causes self
to use its LowerHex
implementation when
Debug
-formatted. Read more
Causes self
to use its Octal
implementation when Debug
-formatted.
fn fmt_pointer(self) -> FmtPointer<Self> where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self> where
Self: Pointer,
Causes self
to use its Pointer
implementation when
Debug
-formatted. Read more
fn fmt_upper_exp(self) -> FmtUpperExp<Self> where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self> where
Self: UpperExp,
Causes self
to use its UpperExp
implementation when
Debug
-formatted. Read more
fn fmt_upper_hex(self) -> FmtUpperHex<Self> where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self> where
Self: UpperHex,
Causes self
to use its UpperHex
implementation when
Debug
-formatted. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
impl<M, S, Target, Request> MakeService<Target, Request> for M where
S: Service<Request>,
M: Service<Target, Response = S>,
impl<M, S, Target, Request> MakeService<Target, Request> for M where
S: Service<Request>,
M: Service<Target, Response = S>,
pub fn poll_ready(
&mut self,
cx: &mut Context<'_>
) -> Poll<Result<(), <M as MakeService<Target, Request>>::MakeError>>
pub fn poll_ready(
&mut self,
cx: &mut Context<'_>
) -> Poll<Result<(), <M as MakeService<Target, Request>>::MakeError>>
Returns Poll::Ready
when the factory is able to create more services. Read more
Create and return a new service value asynchronously.
Consume this MakeService
and convert it into a Service
. Read more
Convert this MakeService
into a Service
without consuming the original MakeService
. Read more
impl<T> Pipe for T where
T: ?Sized,
impl<T> Pipe for T where
T: ?Sized,
Pipes by value. This is generally the method you want to use. Read more
Borrows self
and passes that borrow into the pipe function. Read more
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R where
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R where
R: 'a,
Mutably borrows self
and passes that borrow into the pipe function. Read more
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R where
Self: Borrow<B>,
R: 'a,
B: 'a + ?Sized,
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R where
Self: Borrow<B>,
R: 'a,
B: 'a + ?Sized,
Borrows self
, then passes self.borrow()
into the pipe function. Read more
fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> R where
Self: BorrowMut<B>,
R: 'a,
B: 'a + ?Sized,
fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> R where
Self: BorrowMut<B>,
R: 'a,
B: 'a + ?Sized,
Mutably borrows self
, then passes self.borrow_mut()
into the pipe
function. Read more
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R where
Self: AsRef<U>,
R: 'a,
U: 'a + ?Sized,
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R where
Self: AsRef<U>,
R: 'a,
U: 'a + ?Sized,
Borrows self
, then passes self.as_ref()
into the pipe function.
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R where
Self: AsMut<U>,
R: 'a,
U: 'a + ?Sized,
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R where
Self: AsMut<U>,
R: 'a,
U: 'a + ?Sized,
Mutably borrows self
, then passes self.as_mut()
into the pipe
function. Read more
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: Deref<Target = T>,
R: 'a,
T: 'a + ?Sized,
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: Deref<Target = T>,
R: 'a,
T: 'a + ?Sized,
Borrows self
, then passes self.deref()
into the pipe function.
fn pipe_as_ref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: AsRef<T>,
R: 'a,
T: 'a,
fn pipe_as_ref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: AsRef<T>,
R: 'a,
T: 'a,
Pipes a trait borrow into a function that cannot normally be called in suffix position. Read more
fn pipe_as_mut<'a, T, R>(&'a mut self, func: impl FnOnce(&'a mut T) -> R) -> R where
Self: AsMut<T>,
R: 'a,
T: 'a,
fn pipe_as_mut<'a, T, R>(&'a mut self, func: impl FnOnce(&'a mut T) -> R) -> R where
Self: AsMut<T>,
R: 'a,
T: 'a,
Pipes a trait mutable borrow into a function that cannot normally be called in suffix position. Read more
fn pipe_borrow<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: Borrow<T>,
R: 'a,
T: 'a,
fn pipe_borrow<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: Borrow<T>,
R: 'a,
T: 'a,
Pipes a trait borrow into a function that cannot normally be called in suffix position. Read more
fn pipe_borrow_mut<'a, T, R>(
&'a mut self,
func: impl FnOnce(&'a mut T) -> R
) -> R where
Self: BorrowMut<T>,
R: 'a,
T: 'a,
fn pipe_borrow_mut<'a, T, R>(
&'a mut self,
func: impl FnOnce(&'a mut T) -> R
) -> R where
Self: BorrowMut<T>,
R: 'a,
T: 'a,
Pipes a trait mutable borrow into a function that cannot normally be called in suffix position. Read more
fn pipe_deref<'a, R>(&'a self, func: impl FnOnce(&'a Self::Target) -> R) -> R where
Self: Deref,
R: 'a,
fn pipe_deref<'a, R>(&'a self, func: impl FnOnce(&'a Self::Target) -> R) -> R where
Self: Deref,
R: 'a,
Pipes a dereference into a function that cannot normally be called in suffix position. Read more
fn pipe_deref_mut<'a, R>(
&'a mut self,
func: impl FnOnce(&'a mut Self::Target) -> R
) -> R where
Self: DerefMut,
R: 'a,
fn pipe_deref_mut<'a, R>(
&'a mut self,
func: impl FnOnce(&'a mut Self::Target) -> R
) -> R where
Self: DerefMut,
R: 'a,
Pipes a mutable dereference into a function that cannot normally be called in suffix position. Read more
Pipes a reference into a function that cannot ordinarily be called in suffix position. Read more
Create a new Policy
that returns Action::Follow
only if self
and other
return
Action::Follow
. Read more
type Output = T
type Output = T
Should always be Self
Yields a mutable reference to the service when it is ready to accept a request.
please use the ServiceExt::ready
method instead
Yields a mutable reference to the service when it is ready to accept a request.
Yields the service when it is ready to accept a request.
Consume this Service
, calling with the providing request once it is ready.
Executes a new future after this service’s future resolves. This does
not alter the behaviour of the poll_ready
method. Read more
fn map_response<F, Response>(self, f: F) -> MapResponse<Self, F> where
F: FnOnce(Self::Response) -> Response + Clone,
fn map_response<F, Response>(self, f: F) -> MapResponse<Self, F> where
F: FnOnce(Self::Response) -> Response + Clone,
Maps this service’s response value to a different value. This does not
alter the behaviour of the poll_ready
method. Read more
Maps this service’s error value to a different value. This does not
alter the behaviour of the poll_ready
method. Read more
Maps this service’s result type (Result<Self::Response, Self::Error>
)
to a different value, regardless of whether the future succeeds or
fails. Read more
fn map_request<F, NewRequest>(self, f: F) -> MapRequest<Self, F> where
F: FnMut(NewRequest) -> Request + Clone,
fn map_request<F, NewRequest>(self, f: F) -> MapRequest<Self, F> where
F: FnMut(NewRequest) -> Request + Clone,
Composes a function in front of the service. Read more
fn filter_async<F, NewRequest>(self, filter: F) -> AsyncFilter<Self, F> where
F: AsyncPredicate<NewRequest>,
fn filter_async<F, NewRequest>(self, filter: F) -> AsyncFilter<Self, F> where
F: AsyncPredicate<NewRequest>,
Composes this service with an AsyncFilter
that conditionally accepts or
rejects requests based on an [async predicate]. Read more
Composes an asynchronous function after this service. Read more
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
Immutable access to the Borrow<B>
of a value. Read more
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
Mutable access to the BorrowMut<B>
of a value. Read more
Immutable access to the AsRef<R>
view of a value. Read more
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
Mutable access to the AsMut<R>
view of a value. Read more
Immutable access to the Deref::Target
of a value. Read more
Mutable access to the Deref::Target
of a value. Read more
Calls .tap()
only in debug builds, and is erased in release builds.
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
Calls .tap_mut()
only in debug builds, and is erased in release
builds. Read more
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
Calls .tap_borrow()
only in debug builds, and is erased in release
builds. Read more
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
Calls .tap_borrow_mut()
only in debug builds, and is erased in release
builds. Read more
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self where
Self: AsRef<R>,
R: ?Sized,
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self where
Self: AsRef<R>,
R: ?Sized,
Calls .tap_ref()
only in debug builds, and is erased in release
builds. Read more
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
Calls .tap_ref_mut()
only in debug builds, and is erased in release
builds. Read more
Provides immutable access for inspection. Read more
Calls tap
in debug builds, and does nothing in release builds.
Provides mutable access for modification. Read more
fn tap_mut_dbg<F, R>(self, func: F) -> Self where
F: FnOnce(&mut Self) -> R,
fn tap_mut_dbg<F, R>(self, func: F) -> Self where
F: FnOnce(&mut Self) -> R,
Calls tap_mut
in debug builds, and does nothing in release builds.
impl<T, U> TapAsRef<U> for T where
U: ?Sized,
impl<T, U> TapAsRef<U> for T where
U: ?Sized,
Provides immutable access to the reference for inspection.
fn tap_ref_dbg<F, R>(self, func: F) -> Self where
Self: AsRef<T>,
F: FnOnce(&T) -> R,
fn tap_ref_dbg<F, R>(self, func: F) -> Self where
Self: AsRef<T>,
F: FnOnce(&T) -> R,
Calls tap_ref
in debug builds, and does nothing in release builds.
fn tap_ref_mut<F, R>(self, func: F) -> Self where
Self: AsMut<T>,
F: FnOnce(&mut T) -> R,
fn tap_ref_mut<F, R>(self, func: F) -> Self where
Self: AsMut<T>,
F: FnOnce(&mut T) -> R,
Provides mutable access to the reference for modification.
fn tap_ref_mut_dbg<F, R>(self, func: F) -> Self where
Self: AsMut<T>,
F: FnOnce(&mut T) -> R,
fn tap_ref_mut_dbg<F, R>(self, func: F) -> Self where
Self: AsMut<T>,
F: FnOnce(&mut T) -> R,
Calls tap_ref_mut
in debug builds, and does nothing in release builds.
impl<T, U> TapBorrow<U> for T where
U: ?Sized,
impl<T, U> TapBorrow<U> for T where
U: ?Sized,
fn tap_borrow<F, R>(self, func: F) -> Self where
Self: Borrow<T>,
F: FnOnce(&T) -> R,
fn tap_borrow<F, R>(self, func: F) -> Self where
Self: Borrow<T>,
F: FnOnce(&T) -> R,
Provides immutable access to the borrow for inspection. Read more
fn tap_borrow_dbg<F, R>(self, func: F) -> Self where
Self: Borrow<T>,
F: FnOnce(&T) -> R,
fn tap_borrow_dbg<F, R>(self, func: F) -> Self where
Self: Borrow<T>,
F: FnOnce(&T) -> R,
Calls tap_borrow
in debug builds, and does nothing in release builds.
fn tap_borrow_mut<F, R>(self, func: F) -> Self where
Self: BorrowMut<T>,
F: FnOnce(&mut T) -> R,
fn tap_borrow_mut<F, R>(self, func: F) -> Self where
Self: BorrowMut<T>,
F: FnOnce(&mut T) -> R,
Provides mutable access to the borrow for modification.
fn tap_borrow_mut_dbg<F, R>(self, func: F) -> Self where
Self: BorrowMut<T>,
F: FnOnce(&mut T) -> R,
fn tap_borrow_mut_dbg<F, R>(self, func: F) -> Self where
Self: BorrowMut<T>,
F: FnOnce(&mut T) -> R,
Calls tap_borrow_mut
in debug builds, and does nothing in release
builds. Read more
Immutably dereferences self
for inspection.
fn tap_deref_dbg<F, R>(self, func: F) -> Self where
Self: Deref,
F: FnOnce(&Self::Target) -> R,
fn tap_deref_dbg<F, R>(self, func: F) -> Self where
Self: Deref,
F: FnOnce(&Self::Target) -> R,
Calls tap_deref
in debug builds, and does nothing in release builds.
fn tap_deref_mut<F, R>(self, func: F) -> Self where
Self: DerefMut,
F: FnOnce(&mut Self::Target) -> R,
fn tap_deref_mut<F, R>(self, func: F) -> Self where
Self: DerefMut,
F: FnOnce(&mut Self::Target) -> R,
Mutably dereferences self
for modification.
fn tap_deref_mut_dbg<F, R>(self, func: F) -> Self where
Self: DerefMut,
F: FnOnce(&mut Self::Target) -> R,
fn tap_deref_mut_dbg<F, R>(self, func: F) -> Self where
Self: DerefMut,
F: FnOnce(&mut Self::Target) -> R,
Calls tap_deref_mut
in debug builds, and does nothing in release
builds. Read more