Link

Struct Link 

Source
pub struct Link { /* private fields */ }
Expand description

A single Link in the greater Chain

Wraps an Actix-Web service factory with details on when the service should be evaluated in the chain and if processing should continue afterwards.

§Examples

use actix_web::{App, guard::Header, http::StatusCode, web};
use actix_chain::{Chain, Link, next::IsStatus};

async fn index() -> &'static str {
    "Hello World!"
}

Link::new(web::get().to(index))
    .prefix("/index")
    .guard(Header("Host", "example.com"))
    .next(IsStatus(StatusCode::NOT_FOUND));

Implementations§

Source

pub fn new<F, U>(service: F) -> Self
where F: IntoServiceFactory<U, ServiceRequest>, U: ServiceFactory<ServiceRequest, Config = (), Response = ServiceResponse, Error = Error> + 'static,

Create a new Link for your Chain.

Any Actix-Web service can be passed such as actix_web::Route.

Source

pub fn prefix<S: Into<String>>(self, prefix: S) -> Self

Assign a match-prefix / mount_path to the link.

The prefix is the root URL at which the service is used. For example, /assets will serve files at example.com/assets/….

Source

pub fn guard<G: Guard + 'static>(self, guards: G) -> Self

Adds a routing guard.

Use this to allow multiple chained services that respond to strictly different properties of a request.

IMPORTANT: If a guard supplied here does not match a given request, the request WILL be forwarded to the next Link in the chain, unlike Chain::guard

§Examples
use actix_web::{guard::Header, App, web};
use actix_chain::{Chain, Link};

async fn index() -> &'static str {
    "Hello world!"
}

let svc = web::get().to(index);
Chain::default()
    .link(Link::new(svc)
        .guard(Header("Host", "example.com")));
Source

pub fn next<N>(self, next: N) -> Self
where N: Next + 'static,

Configure when a Link should forward to the next chain instead of returning its ServiceResponse.

Any responses that match the supplied criteria will instead be ignored, assuming another link exists within the chain.

The default Link behavior is to continue down the chain on “404 Not Found” responses only.

§Examples
use actix_web::{http::StatusCode, web};
use actix_chain::{Link, next::IsStatus};

async fn index() -> &'static str {
    "Hello world!"
}

Link::new(web::get().to(index))
    .next(IsStatus(StatusCode::NOT_FOUND));

Trait Implementations§

Source§

fn clone(&self) -> Link

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

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

Source§

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

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

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,