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§impl Link
impl Link
Sourcepub fn new<F, U>(service: F) -> Selfwhere
F: IntoServiceFactory<U, ServiceRequest>,
U: ServiceFactory<ServiceRequest, Config = (), Response = ServiceResponse, Error = Error> + 'static,
pub fn new<F, U>(service: F) -> Selfwhere
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.
Sourcepub fn prefix<S: Into<String>>(self, prefix: S) -> Self
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/….
Sourcepub fn guard<G: Guard + 'static>(self, guards: G) -> Self
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")));Sourcepub fn next<N>(self, next: N) -> Selfwhere
N: Next + 'static,
pub fn next<N>(self, next: N) -> Selfwhere
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));