Struct Redirect

#[must_use = "needs to be returned from a handler or otherwise turned into a Response to be useful"]
pub struct Redirect { /* private fields */ }

Response that redirects the request to another location.

Example

use axum::{
    routing::get,
    response::Redirect,
    Router,
};

let app = Router::new()
    .route("/old", get(|| async { Redirect::permanent("/new") }))
    .route("/new", get(|| async { "Hello!" }));
# let _: Router = app;

Implementations

impl Redirect

fn to(uri: &str) -> Self

Create a new Redirect that uses a 303 See Other status code.

This redirect instructs the client to change the method to GET for the subsequent request to the given uri, which is useful after successful form submission, file upload or when you generally don't want the redirected-to page to observe the original request method and body (if non-empty). If you want to preserve the request method and body, Redirect::temporary should be used instead.

fn temporary(uri: &str) -> Self

Create a new Redirect that uses a 307 Temporary Redirect status code.

This has the same behavior as Redirect::to, except it will preserve the original HTTP method and body.

fn permanent(uri: &str) -> Self

Create a new Redirect that uses a 308 Permanent Redirect status code.

fn status_code(&self) -> StatusCode

Returns the HTTP status code of the Redirect.

fn location(&self) -> &str

Returns the Redirect's URI.

Trait Implementations

impl Clone for Redirect

fn clone(&self) -> Redirect

impl Debug for Redirect

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

impl IntoResponse for Redirect

fn into_response(self) -> Response

Auto Trait Implementations

impl Freeze for Redirect

impl RefUnwindSafe for Redirect

impl Send for Redirect

impl Sync for Redirect

impl Unpin for Redirect

impl UnsafeUnpin for Redirect

impl UnwindSafe for Redirect

Blanket Implementations

impl<H, T> HandlerWithoutStateExt<T> for Redirect where H: Handler<T, ()>,

fn into_service(self) -> HandlerService<H, T, ()>
fn into_make_service(self) -> IntoMakeService<HandlerService<H, T, ()>>
fn into_make_service_with_connect_info<C>(self) -> IntoMakeServiceWithConnectInfo<HandlerService<H, T, ()>, C>

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for Redirect where ST: ?Sized, DT: ?Sized,

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for Redirect where ST: ?Sized, DT: ?Sized,

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

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for Redirect where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for Redirect where T: ?Sized,

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

impl<T> CloneToUninit for Redirect where T: Clone,

unsafe fn clone_to_uninit(&self, dest: *mut u8)

impl<T> From<T> for Redirect

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> FromRef<T> for Redirect where T: Clone,

fn from_ref(input: &T) -> T

impl<T> Instrument for Redirect

impl<T> Read<Exclusive, BecauseExclusive> for Redirect where T: ?Sized,

impl<T> Same for Redirect

type Output = T;

impl<T> ToOwned for Redirect where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T> WithSubscriber for Redirect

impl<T, U> Into<U> for Redirect where U: From<T>,

fn into(self) -> U

Calls U::from(self).

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

impl<T, U> TryFrom<U> for Redirect where U: Into<T>,

type Error = never;
fn try_from(value: U) -> Result<T, never>

impl<T, U> TryInto<U> for Redirect where U: TryFrom<T>,

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

impl<V, T> VZip<V> for Redirect where V: MultiLane<T>,

fn vzip(self) -> V