Skip to main content

RedirectExt

Trait RedirectExt 

Source
pub trait RedirectExt: Sealed + Sized {
    // Required methods
    fn route(name: &str, params: &[&dyn Display]) -> Result<Self>;
    fn intended(session: &Session, fallback: &str) -> Self;
}
Expand description

Named-route and intended-page redirects on axum’s Redirect (in the prelude):

// To a named route, with its parameters:
let to_product = Redirect::route("products.show", &[&id])?;
// Where a guard sent the user from (e.g. before logging in), else /dashboard:
let back = Redirect::intended(&session, "/dashboard");

The trait is sealed: it’s implemented for Redirect only, so it can grow.

Required Methods§

Source

fn route(name: &str, params: &[&dyn Display]) -> Result<Self>

A 303 redirect to the named route name with params filling its {…} placeholders in order. Needs the app, so it works in handlers, middleware, jobs and commands (not in code outside any of them).

Source

fn intended(session: &Session, fallback: &str) -> Self

A 303 redirect to the page a guard stored before sending the user away (require_auth keeps the page that asked for a login), or to fallback. The stored page is used once and only if it’s on this site.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl RedirectExt for Redirect

Source§

fn route(name: &str, params: &[&dyn Display]) -> Result<Self>

Source§

fn intended(session: &Session, fallback: &str) -> Self

Implementors§