mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-23 16:21:06 +01:00
179 lines
46 KiB
HTML
179 lines
46 KiB
HTML
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="A collection of `Route`s, `Resource`s, or other services that share a common path prefix."><title>Scope in actix_web - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-46f98efaafac5295.ttf.woff2,FiraSans-Regular-018c141bf0843ffd.woff2,FiraSans-Medium-8f9a781e4970d388.woff2,SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2,SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../static.files/rustdoc-dd39b87e5fcfba68.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="actix_web" data-themes="" data-resource-suffix="" data-rustdoc-version="1.80.0-nightly (bdbbb6c6a 2024-05-26)" data-channel="nightly" data-search-js="search-d52510db62a78183.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="../static.files/storage-118b08c4c78b968e.js"></script><script defer src="sidebar-items.js"></script><script defer src="../static.files/main-20a3ad099b048cf2.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-df360f571f6edeae.css"></noscript><link rel="icon" href="https://actix.rs/favicon.ico"></head><body class="rustdoc struct"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button><a class="logo-container" href="../actix_web/index.html"><img src="https://actix.rs/img/logo.png" alt=""></a></nav><nav class="sidebar"><div class="sidebar-crate"><a class="logo-container" href="../actix_web/index.html"><img src="https://actix.rs/img/logo.png" alt="logo"></a><h2><a href="../actix_web/index.html">actix_web</a><span class="version">4.6.0</span></h2></div><h2 class="location"><a href="#">Scope</a></h2><div class="sidebar-elems"><section><h3><a href="#implementations">Methods</a></h3><ul class="block method"><li><a href="#method.app_data">app_data</a></li><li><a href="#method.configure">configure</a></li><li><a href="#method.data">data</a></li><li><a href="#method.default_service">default_service</a></li><li><a href="#method.guard">guard</a></li><li><a href="#method.new">new</a></li><li><a href="#method.route">route</a></li><li><a href="#method.service">service</a></li><li><a href="#method.wrap">wrap</a></li><li><a href="#method.wrap_fn">wrap_fn</a></li></ul><h3><a href="#trait-implementations">Trait Implementations</a></h3><ul class="block trait-implementation"><li><a href="#impl-HttpServiceFactory-for-Scope%3CT%3E">HttpServiceFactory</a></li></ul><h3><a href="#synthetic-implementations">Auto Trait Implementations</a></h3><ul class="block synthetic-implementation"><li><a href="#impl-RefUnwindSafe-for-Scope%3CT%3E">!RefUnwindSafe</a></li><li><a href="#impl-Send-for-Scope%3CT%3E">!Send</a></li><li><a href="#impl-Sync-for-Scope%3CT%3E">!Sync</a></li><li><a href="#impl-UnwindSafe-for-Scope%3CT%3E">!UnwindSafe</a></li><li><a href="#impl-Freeze-for-Scope%3CT%3E">Freeze</a></li><li><a href="#impl-Unpin-for-Scope%3CT%3E">Unpin</a></li></ul><h3><a href="#blanket-implementations">Blanket Implementations</a></h3><ul class="block blanket-implementation"><li><a href="#impl-Any-for-T">Any</a></li><li><a href="#impl-Borrow%3CT%3E-for-T">Borrow<T></a></li><li><a href="#impl-BorrowMut%3CT%3E-for-T">BorrowMut<T></a></li><li><a href="#impl-From%3CT%3E-for-T">From<T></a></li><li><a href="#impl-Instrument-for-T">Instrument</a></li><li><a href="#impl-Into%3CU%3E-for-T">Into<U></a></li><li><a href="#impl-Same-for-T">Same</a></li><li><a href="#impl-TryFrom%3CU%3E-for-T">TryFrom<U></a></li><li><a href="#impl-TryInto%3CU%3E-for-T">TryInto<U></a></li><li><a href="#impl-VZip%3CV%3E-for-T">VZip<V></a></li><li><a href="#impl-WithSubscriber-for-T">WithSubscriber</a></li></ul></section><h2><a href="index.html">In crate actix_web</a></h2></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><h1>Struct <a href="index.html">actix_web</a>::<wbr><a class="struct" href="#">Scope</a><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><span class="out-of-band"><a class="src" href="../src/actix_web/scope.rs.html#57-66">source</a> · <button id="toggle-all-docs" title="collapse all docs">[<span>−</span>]</button></span></div><pre class="rust item-decl"><code>pub struct Scope<T = ScopeEndpoint> { <span class="comment">/* private fields */</span> }</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>A collection of <a href="struct.Route.html" title="struct actix_web::Route"><code>Route</code></a>s, <a href="struct.Resource.html" title="struct actix_web::Resource"><code>Resource</code></a>s, or other services that share a common path prefix.</p>
|
||
<p>The <code>Scope</code>’s path can contain <a href="dev/struct.ResourceDef.html#dynamic-segments" title="struct actix_web::dev::ResourceDef">dynamic segments</a>. The dynamic segments can be extracted from
|
||
requests using the <a href="web/struct.Path.html" title="struct actix_web::web::Path"><code>Path</code></a> extractor or
|
||
with <a href="struct.HttpRequest.html#method.match_info" title="method actix_web::HttpRequest::match_info"><code>HttpRequest::match_info()</code></a>.</p>
|
||
<h2 id="avoid-trailing-slashes"><a class="doc-anchor" href="#avoid-trailing-slashes">§</a>Avoid Trailing Slashes</h2>
|
||
<p>Avoid using trailing slashes in the scope prefix (e.g., <code>web::scope("/scope/")</code>). It will almost
|
||
certainly not have the expected behavior. See the <a href="dev/struct.ResourceDef.html#prefix-resources" title="struct actix_web::dev::ResourceDef">documentation on resource definitions</a>
|
||
to understand why this is the case and how to correctly construct scope/prefix definitions.</p>
|
||
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>actix_web::{web, App, HttpResponse};
|
||
|
||
<span class="kw">let </span>app = App::new().service(
|
||
web::scope(<span class="string">"/{project_id}"</span>)
|
||
.service(web::resource(<span class="string">"/path1"</span>).to(|| <span class="kw">async </span>{ <span class="string">"OK" </span>}))
|
||
.service(web::resource(<span class="string">"/path2"</span>).route(web::get().to(|| HttpResponse::Ok())))
|
||
.service(web::resource(<span class="string">"/path3"</span>).route(web::head().to(HttpResponse::MethodNotAllowed)))
|
||
);</code></pre></div>
|
||
<p>In the above example three routes get registered:</p>
|
||
<ul>
|
||
<li>/{project_id}/path1 - responds to all HTTP methods</li>
|
||
<li>/{project_id}/path2 - responds to <code>GET</code> requests</li>
|
||
<li>/{project_id}/path3 - responds to <code>HEAD</code> requests</li>
|
||
</ul>
|
||
</div></details><h2 id="implementations" class="section-header">Implementations<a href="#implementations" class="anchor">§</a></h2><div id="implementations-list"><details class="toggle implementors-toggle" open><summary><section id="impl-Scope" class="impl"><a class="src rightside" href="../src/actix_web/scope.rs.html#68-84">source</a><a href="#impl-Scope" class="anchor">§</a><h3 class="code-header">impl <a class="struct" href="struct.Scope.html" title="struct actix_web::Scope">Scope</a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.new" class="method"><a class="src rightside" href="../src/actix_web/scope.rs.html#70-83">source</a><h4 class="code-header">pub fn <a href="#method.new" class="fn">new</a>(path: &<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>) -> <a class="struct" href="struct.Scope.html" title="struct actix_web::Scope">Scope</a></h4></section></summary><div class="docblock"><p>Create a new scope</p>
|
||
</div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-Scope%3CT%3E" class="impl"><a class="src rightside" href="../src/actix_web/scope.rs.html#86-367">source</a><a href="#impl-Scope%3CT%3E" class="anchor">§</a><h3 class="code-header">impl<T> <a class="struct" href="struct.Scope.html" title="struct actix_web::Scope">Scope</a><T><div class="where">where
|
||
T: <a class="trait" href="dev/trait.ServiceFactory.html" title="trait actix_web::dev::ServiceFactory">ServiceFactory</a><<a class="struct" href="dev/struct.ServiceRequest.html" title="struct actix_web::dev::ServiceRequest">ServiceRequest</a>, Config = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Error = <a class="struct" href="error/struct.Error.html" title="struct actix_web::error::Error">Error</a>, InitError = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.guard" class="method"><a class="src rightside" href="../src/actix_web/scope.rs.html#108-111">source</a><h4 class="code-header">pub fn <a href="#method.guard" class="fn">guard</a><G: <a class="trait" href="guard/trait.Guard.html" title="trait actix_web::guard::Guard">Guard</a> + 'static>(self, guard: G) -> Self</h4></section></summary><div class="docblock"><p>Add match guard to a scope.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>actix_web::{web, guard, App, HttpRequest, HttpResponse};
|
||
|
||
<span class="kw">async fn </span>index(data: web::Path<(String, String)>) -> <span class="kw-2">&</span><span class="lifetime">'static </span>str {
|
||
<span class="string">"Welcome!"
|
||
</span>}
|
||
|
||
<span class="kw">let </span>app = App::new().service(
|
||
web::scope(<span class="string">"/app"</span>)
|
||
.guard(guard::Header(<span class="string">"content-type"</span>, <span class="string">"text/plain"</span>))
|
||
.route(<span class="string">"/test1"</span>, web::get().to(index))
|
||
.route(<span class="string">"/test2"</span>, web::post().to(|r: HttpRequest| {
|
||
HttpResponse::MethodNotAllowed()
|
||
}))
|
||
);</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.app_data" class="method"><a class="src rightside" href="../src/actix_web/scope.rs.html#146-152">source</a><h4 class="code-header">pub fn <a href="#method.app_data" class="fn">app_data</a><U: 'static>(self, data: U) -> Self</h4></section></summary><div class="docblock"><p>Add scope data.</p>
|
||
<p>Data of different types from parent contexts will still be accessible. Any <code>Data<T></code> types
|
||
set here can be extracted in handlers using the <code>Data<T></code> extractor.</p>
|
||
<h5 id="examples-1"><a class="doc-anchor" href="#examples-1">§</a>Examples</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::cell::Cell;
|
||
<span class="kw">use </span>actix_web::{web, App, HttpRequest, HttpResponse, Responder};
|
||
|
||
<span class="kw">struct </span>MyData {
|
||
count: std::cell::Cell<usize>,
|
||
}
|
||
|
||
<span class="kw">async fn </span>handler(req: HttpRequest, counter: web::Data<MyData>) -> <span class="kw">impl </span>Responder {
|
||
<span class="comment">// note this cannot use the Data<T> extractor because it was not added with it
|
||
</span><span class="kw">let </span>incr = <span class="kw-2">*</span>req.app_data::<usize>().unwrap();
|
||
<span class="macro">assert_eq!</span>(incr, <span class="number">3</span>);
|
||
|
||
<span class="comment">// update counter using other value from app data
|
||
</span>counter.count.set(counter.count.get() + incr);
|
||
|
||
HttpResponse::Ok().body(counter.count.get().to_string())
|
||
}
|
||
|
||
<span class="kw">let </span>app = App::new().service(
|
||
web::scope(<span class="string">"/app"</span>)
|
||
.app_data(<span class="number">3usize</span>)
|
||
.app_data(web::Data::new(MyData { count: Default::default() }))
|
||
.route(<span class="string">"/"</span>, web::get().to(handler))
|
||
);</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.data" class="method"><a class="src rightside" href="../src/actix_web/scope.rs.html#158-160">source</a><h4 class="code-header">pub fn <a href="#method.data" class="fn">data</a><U: 'static>(self, data: U) -> Self</h4></section><span class="item-info"><div class="stab deprecated"><span class="emoji">👎</span><span>Deprecated since 4.0.0: Use <code>.app_data(Data::new(val))</code> instead.</span></div></span></summary><div class="docblock"><p>Add scope data after wrapping in <code>Data<T></code>.</p>
|
||
<p>Deprecated in favor of <a href="struct.Scope.html#method.app_data" title="method actix_web::Scope::app_data"><code>app_data</code></a>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.configure" class="method"><a class="src rightside" href="../src/actix_web/scope.rs.html#186-206">source</a><h4 class="code-header">pub fn <a href="#method.configure" class="fn">configure</a><F>(self, cfg_fn: F) -> Self<div class="where">where
|
||
F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>(&mut <a class="struct" href="web/struct.ServiceConfig.html" title="struct actix_web::web::ServiceConfig">ServiceConfig</a>),</div></h4></section></summary><div class="docblock"><p>Run external configuration as part of the scope building process.</p>
|
||
<p>This function is useful for moving parts of configuration to a different module or library.
|
||
For example, some of the resource’s configuration could be moved to different module.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>actix_web::{web, middleware, App, HttpResponse};
|
||
|
||
<span class="comment">// this function could be located in different module
|
||
</span><span class="kw">fn </span>config(cfg: <span class="kw-2">&mut </span>web::ServiceConfig) {
|
||
cfg.service(web::resource(<span class="string">"/test"</span>)
|
||
.route(web::get().to(|| HttpResponse::Ok()))
|
||
.route(web::head().to(|| HttpResponse::MethodNotAllowed()))
|
||
);
|
||
}
|
||
|
||
<span class="kw">let </span>app = App::new()
|
||
.wrap(middleware::Logger::default())
|
||
.service(
|
||
web::scope(<span class="string">"/api"</span>)
|
||
.configure(config)
|
||
)
|
||
.route(<span class="string">"/index.html"</span>, web::get().to(|| HttpResponse::Ok()));</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.service" class="method"><a class="src rightside" href="../src/actix_web/scope.rs.html#233-240">source</a><h4 class="code-header">pub fn <a href="#method.service" class="fn">service</a><F>(self, factory: F) -> Self<div class="where">where
|
||
F: <a class="trait" href="dev/trait.HttpServiceFactory.html" title="trait actix_web::dev::HttpServiceFactory">HttpServiceFactory</a> + 'static,</div></h4></section></summary><div class="docblock"><p>Register HTTP service.</p>
|
||
<p>This is similar to <code>App's</code> service registration.</p>
|
||
<p>Actix Web provides several services implementations:</p>
|
||
<ul>
|
||
<li><em>Resource</em> is an entry in resource table which corresponds to requested URL.</li>
|
||
<li><em>Scope</em> is a set of resources with common root path.</li>
|
||
<li>“StaticFiles” is a service for static files support</li>
|
||
</ul>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>actix_web::{web, App, HttpRequest};
|
||
|
||
<span class="kw">struct </span>AppState;
|
||
|
||
<span class="kw">async fn </span>index(req: HttpRequest) -> <span class="kw-2">&</span><span class="lifetime">'static </span>str {
|
||
<span class="string">"Welcome!"
|
||
</span>}
|
||
|
||
<span class="kw">let </span>app = App::new().service(
|
||
web::scope(<span class="string">"/app"</span>).service(
|
||
web::scope(<span class="string">"/v1"</span>)
|
||
.service(web::resource(<span class="string">"/test1"</span>).to(index)))
|
||
);</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.route" class="method"><a class="src rightside" href="../src/actix_web/scope.rs.html#261-267">source</a><h4 class="code-header">pub fn <a href="#method.route" class="fn">route</a>(self, path: &<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>, route: <a class="struct" href="struct.Route.html" title="struct actix_web::Route">Route</a>) -> Self</h4></section></summary><div class="docblock"><p>Configure route for a specific path.</p>
|
||
<p>This is a simplified version of the <code>Scope::service()</code> method.
|
||
This method can be called multiple times, in that case
|
||
multiple resources with one route would be registered for same resource path.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>actix_web::{web, App, HttpResponse};
|
||
|
||
<span class="kw">async fn </span>index(data: web::Path<(String, String)>) -> <span class="kw-2">&</span><span class="lifetime">'static </span>str {
|
||
<span class="string">"Welcome!"
|
||
</span>}
|
||
|
||
<span class="kw">let </span>app = App::new().service(
|
||
web::scope(<span class="string">"/app"</span>)
|
||
.route(<span class="string">"/test1"</span>, web::get().to(index))
|
||
.route(<span class="string">"/test2"</span>, web::post().to(|| HttpResponse::MethodNotAllowed()))
|
||
);</code></pre></div>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.default_service" class="method"><a class="src rightside" href="../src/actix_web/scope.rs.html#273-286">source</a><h4 class="code-header">pub fn <a href="#method.default_service" class="fn">default_service</a><F, U>(self, f: F) -> Self<div class="where">where
|
||
F: IntoServiceFactory<U, <a class="struct" href="dev/struct.ServiceRequest.html" title="struct actix_web::dev::ServiceRequest">ServiceRequest</a>>,
|
||
U: <a class="trait" href="dev/trait.ServiceFactory.html" title="trait actix_web::dev::ServiceFactory">ServiceFactory</a><<a class="struct" href="dev/struct.ServiceRequest.html" title="struct actix_web::dev::ServiceRequest">ServiceRequest</a>, Config = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Response = <a class="struct" href="dev/struct.ServiceResponse.html" title="struct actix_web::dev::ServiceResponse">ServiceResponse</a>, Error = <a class="struct" href="error/struct.Error.html" title="struct actix_web::error::Error">Error</a>> + 'static,
|
||
U::<a class="associatedtype" href="dev/trait.ServiceFactory.html#associatedtype.InitError" title="type actix_web::dev::ServiceFactory::InitError">InitError</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a>,</div></h4></section></summary><div class="docblock"><p>Default service to be used if no matching resource could be found.</p>
|
||
<p>If a default service is not registered, it will fall back to the default service of
|
||
the parent <a href="struct.App.html" title="struct actix_web::App"><code>App</code></a> (see <a href="struct.App.html#method.default_service" title="method actix_web::App::default_service"><code>App::default_service</code></a>).</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.wrap" class="method"><a class="src rightside" href="../src/actix_web/scope.rs.html#296-328">source</a><h4 class="code-header">pub fn <a href="#method.wrap" class="fn">wrap</a><M, B>(
|
||
self,
|
||
mw: M
|
||
) -> <a class="struct" href="struct.Scope.html" title="struct actix_web::Scope">Scope</a><impl <a class="trait" href="dev/trait.ServiceFactory.html" title="trait actix_web::dev::ServiceFactory">ServiceFactory</a><<a class="struct" href="dev/struct.ServiceRequest.html" title="struct actix_web::dev::ServiceRequest">ServiceRequest</a>, Config = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Response = <a class="struct" href="dev/struct.ServiceResponse.html" title="struct actix_web::dev::ServiceResponse">ServiceResponse</a><B>, Error = <a class="struct" href="error/struct.Error.html" title="struct actix_web::error::Error">Error</a>, InitError = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>>><div class="where">where
|
||
M: <a class="trait" href="dev/trait.Transform.html" title="trait actix_web::dev::Transform">Transform</a><T::<a class="associatedtype" href="dev/trait.ServiceFactory.html#associatedtype.Service" title="type actix_web::dev::ServiceFactory::Service">Service</a>, <a class="struct" href="dev/struct.ServiceRequest.html" title="struct actix_web::dev::ServiceRequest">ServiceRequest</a>, Response = <a class="struct" href="dev/struct.ServiceResponse.html" title="struct actix_web::dev::ServiceResponse">ServiceResponse</a><B>, Error = <a class="struct" href="error/struct.Error.html" title="struct actix_web::error::Error">Error</a>, InitError = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>> + 'static,
|
||
B: <a class="trait" href="body/trait.MessageBody.html" title="trait actix_web::body::MessageBody">MessageBody</a>,</div></h4></section></summary><div class="docblock"><p>Registers a scope-wide middleware.</p>
|
||
<p><code>mw</code> is a middleware component (type), that can modify the request and response across all
|
||
sub-resources managed by this <code>Scope</code>.</p>
|
||
<p>See <a href="struct.App.html#method.wrap" title="method actix_web::App::wrap"><code>App::wrap</code></a> for more details.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.wrap_fn" class="method"><a class="src rightside" href="../src/actix_web/scope.rs.html#339-366">source</a><h4 class="code-header">pub fn <a href="#method.wrap_fn" class="fn">wrap_fn</a><F, R, B>(
|
||
self,
|
||
mw: F
|
||
) -> <a class="struct" href="struct.Scope.html" title="struct actix_web::Scope">Scope</a><impl <a class="trait" href="dev/trait.ServiceFactory.html" title="trait actix_web::dev::ServiceFactory">ServiceFactory</a><<a class="struct" href="dev/struct.ServiceRequest.html" title="struct actix_web::dev::ServiceRequest">ServiceRequest</a>, Config = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Response = <a class="struct" href="dev/struct.ServiceResponse.html" title="struct actix_web::dev::ServiceResponse">ServiceResponse</a><B>, Error = <a class="struct" href="error/struct.Error.html" title="struct actix_web::error::Error">Error</a>, InitError = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>>><div class="where">where
|
||
F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(<a class="struct" href="dev/struct.ServiceRequest.html" title="struct actix_web::dev::ServiceRequest">ServiceRequest</a>, &T::<a class="associatedtype" href="dev/trait.ServiceFactory.html#associatedtype.Service" title="type actix_web::dev::ServiceFactory::Service">Service</a>) -> R + <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> + 'static,
|
||
R: <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a><Output = <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="dev/struct.ServiceResponse.html" title="struct actix_web::dev::ServiceResponse">ServiceResponse</a><B>, <a class="struct" href="error/struct.Error.html" title="struct actix_web::error::Error">Error</a>>>,
|
||
B: <a class="trait" href="body/trait.MessageBody.html" title="trait actix_web::body::MessageBody">MessageBody</a>,</div></h4></section></summary><div class="docblock"><p>Registers a scope-wide function middleware.</p>
|
||
<p><code>mw</code> is a closure that runs during inbound and/or outbound processing in the request
|
||
life-cycle (request -> response), modifying request/response as necessary, across all
|
||
requests handled by the <code>Scope</code>.</p>
|
||
<p>See <a href="struct.App.html#method.wrap_fn" title="method actix_web::App::wrap_fn"><code>App::wrap_fn</code></a> for examples and more details.</p>
|
||
</div></details></div></details></div><h2 id="trait-implementations" class="section-header">Trait Implementations<a href="#trait-implementations" class="anchor">§</a></h2><div id="trait-implementations-list"><details class="toggle implementors-toggle" open><summary><section id="impl-HttpServiceFactory-for-Scope%3CT%3E" class="impl"><a class="src rightside" href="../src/actix_web/scope.rs.html#369-441">source</a><a href="#impl-HttpServiceFactory-for-Scope%3CT%3E" class="anchor">§</a><h3 class="code-header">impl<T, B> <a class="trait" href="dev/trait.HttpServiceFactory.html" title="trait actix_web::dev::HttpServiceFactory">HttpServiceFactory</a> for <a class="struct" href="struct.Scope.html" title="struct actix_web::Scope">Scope</a><T><div class="where">where
|
||
T: <a class="trait" href="dev/trait.ServiceFactory.html" title="trait actix_web::dev::ServiceFactory">ServiceFactory</a><<a class="struct" href="dev/struct.ServiceRequest.html" title="struct actix_web::dev::ServiceRequest">ServiceRequest</a>, Config = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Response = <a class="struct" href="dev/struct.ServiceResponse.html" title="struct actix_web::dev::ServiceResponse">ServiceResponse</a><B>, Error = <a class="struct" href="error/struct.Error.html" title="struct actix_web::error::Error">Error</a>, InitError = <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>> + 'static,
|
||
B: <a class="trait" href="body/trait.MessageBody.html" title="trait actix_web::body::MessageBody">MessageBody</a> + 'static,</div></h3></section></summary><div class="impl-items"><section id="method.register" class="method trait-impl"><a class="src rightside" href="../src/actix_web/scope.rs.html#380-440">source</a><a href="#method.register" class="anchor">§</a><h4 class="code-header">fn <a href="dev/trait.HttpServiceFactory.html#tymethod.register" class="fn">register</a>(self, config: &mut <a class="struct" href="dev/struct.AppService.html" title="struct actix_web::dev::AppService">AppService</a>)</h4></section></div></details></div><h2 id="synthetic-implementations" class="section-header">Auto Trait Implementations<a href="#synthetic-implementations" class="anchor">§</a></h2><div id="synthetic-implementations-list"><section id="impl-Freeze-for-Scope%3CT%3E" class="impl"><a href="#impl-Freeze-for-Scope%3CT%3E" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Freeze.html" title="trait core::marker::Freeze">Freeze</a> for <a class="struct" href="struct.Scope.html" title="struct actix_web::Scope">Scope</a><T><div class="where">where
|
||
T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Freeze.html" title="trait core::marker::Freeze">Freeze</a>,</div></h3></section><section id="impl-RefUnwindSafe-for-Scope%3CT%3E" class="impl"><a href="#impl-RefUnwindSafe-for-Scope%3CT%3E" class="anchor">§</a><h3 class="code-header">impl<T = ScopeEndpoint> !<a class="trait" href="https://doc.rust-lang.org/nightly/core/panic/unwind_safe/trait.RefUnwindSafe.html" title="trait core::panic::unwind_safe::RefUnwindSafe">RefUnwindSafe</a> for <a class="struct" href="struct.Scope.html" title="struct actix_web::Scope">Scope</a><T></h3></section><section id="impl-Send-for-Scope%3CT%3E" class="impl"><a href="#impl-Send-for-Scope%3CT%3E" class="anchor">§</a><h3 class="code-header">impl<T = ScopeEndpoint> !<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> for <a class="struct" href="struct.Scope.html" title="struct actix_web::Scope">Scope</a><T></h3></section><section id="impl-Sync-for-Scope%3CT%3E" class="impl"><a href="#impl-Sync-for-Scope%3CT%3E" class="anchor">§</a><h3 class="code-header">impl<T = ScopeEndpoint> !<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> for <a class="struct" href="struct.Scope.html" title="struct actix_web::Scope">Scope</a><T></h3></section><section id="impl-Unpin-for-Scope%3CT%3E" class="impl"><a href="#impl-Unpin-for-Scope%3CT%3E" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a> for <a class="struct" href="struct.Scope.html" title="struct actix_web::Scope">Scope</a><T><div class="where">where
|
||
T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</div></h3></section><section id="impl-UnwindSafe-for-Scope%3CT%3E" class="impl"><a href="#impl-UnwindSafe-for-Scope%3CT%3E" class="anchor">§</a><h3 class="code-header">impl<T = ScopeEndpoint> !<a class="trait" href="https://doc.rust-lang.org/nightly/core/panic/unwind_safe/trait.UnwindSafe.html" title="trait core::panic::unwind_safe::UnwindSafe">UnwindSafe</a> for <a class="struct" href="struct.Scope.html" title="struct actix_web::Scope">Scope</a><T></h3></section></div><h2 id="blanket-implementations" class="section-header">Blanket Implementations<a href="#blanket-implementations" class="anchor">§</a></h2><div id="blanket-implementations-list"><details class="toggle implementors-toggle"><summary><section id="impl-Any-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/nightly/src/core/any.rs.html#140">source</a><a href="#impl-Any-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html" title="trait core::any::Any">Any</a> for T<div class="where">where
|
||
T: 'static + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.type_id" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/nightly/src/core/any.rs.html#141">source</a><a href="#method.type_id" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html#tymethod.type_id" class="fn">type_id</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/nightly/core/any/struct.TypeId.html" title="struct core::any::TypeId">TypeId</a></h4></section></summary><div class='docblock'>Gets the <code>TypeId</code> of <code>self</code>. <a href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html#tymethod.type_id">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Borrow%3CT%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#208">source</a><a href="#impl-Borrow%3CT%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a><T> for T<div class="where">where
|
||
T: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.borrow" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#210">source</a><a href="#method.borrow" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html#tymethod.borrow" class="fn">borrow</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&T</a></h4></section></summary><div class='docblock'>Immutably borrows from an owned value. <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html#tymethod.borrow">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-BorrowMut%3CT%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#216">source</a><a href="#impl-BorrowMut%3CT%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html" title="trait core::borrow::BorrowMut">BorrowMut</a><T> for T<div class="where">where
|
||
T: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.borrow_mut" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#217">source</a><a href="#method.borrow_mut" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut" class="fn">borrow_mut</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut T</a></h4></section></summary><div class='docblock'>Mutably borrows from an owned value. <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-From%3CT%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#765">source</a><a href="#impl-From%3CT%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html" title="trait core::convert::From">From</a><T> for T</h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.from" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#768">source</a><a href="#method.from" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html#tymethod.from" class="fn">from</a>(t: T) -> T</h4></section></summary><div class="docblock"><p>Returns the argument unchanged.</p>
|
||
</div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Instrument-for-T" class="impl"><a href="#impl-Instrument-for-T" class="anchor">§</a><h3 class="code-header">impl<T> Instrument for T</h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.instrument" class="method trait-impl"><a href="#method.instrument" class="anchor">§</a><h4 class="code-header">fn <a class="fn">instrument</a>(self, span: Span) -> Instrumented<Self></h4></section></summary><div class='docblock'>Instruments this type with the provided [<code>Span</code>], returning an
|
||
<code>Instrumented</code> wrapper. <a>Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.in_current_span" class="method trait-impl"><a href="#method.in_current_span" class="anchor">§</a><h4 class="code-header">fn <a class="fn">in_current_span</a>(self) -> Instrumented<Self></h4></section></summary><div class='docblock'>Instruments this type with the <a href="super::Span::current()">current</a> <a href="crate::Span"><code>Span</code></a>, returning an
|
||
<code>Instrumented</code> wrapper. <a>Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Into%3CU%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#748-750">source</a><a href="#impl-Into%3CU%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T, U> <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><U> for T<div class="where">where
|
||
U: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html" title="trait core::convert::From">From</a><T>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.into" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#758">source</a><a href="#method.into" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html#tymethod.into" class="fn">into</a>(self) -> U</h4></section></summary><div class="docblock"><p>Calls <code>U::from(self)</code>.</p>
|
||
<p>That is, this conversion is whatever the implementation of
|
||
<code><a href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html" title="trait core::convert::From">From</a><T> for U</code> chooses to do.</p>
|
||
</div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Same-for-T" class="impl"><a class="src rightside" href="https://docs.rs/typenum/1.17.0/src/typenum/type_operators.rs.html#34">source</a><a href="#impl-Same-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://docs.rs/typenum/1.17.0/typenum/type_operators/trait.Same.html" title="trait typenum::type_operators::Same">Same</a> for T</h3></section></summary><div class="impl-items"><details class="toggle" open><summary><section id="associatedtype.Output" class="associatedtype trait-impl"><a href="#associatedtype.Output" class="anchor">§</a><h4 class="code-header">type <a href="https://docs.rs/typenum/1.17.0/typenum/type_operators/trait.Same.html#associatedtype.Output" class="associatedtype">Output</a> = T</h4></section></summary><div class='docblock'>Should always be <code>Self</code></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-TryFrom%3CU%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#805-807">source</a><a href="#impl-TryFrom%3CU%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T, U> <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><U> for T<div class="where">where
|
||
U: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><T>,</div></h3></section></summary><div class="impl-items"><details class="toggle" open><summary><section id="associatedtype.Error-1" class="associatedtype trait-impl"><a href="#associatedtype.Error-1" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#associatedtype.Error" class="associatedtype">Error</a> = <a class="enum" href="https://doc.rust-lang.org/nightly/core/convert/enum.Infallible.html" title="enum core::convert::Infallible">Infallible</a></h4></section></summary><div class='docblock'>The type returned in the event of a conversion error.</div></details><details class="toggle method-toggle" open><summary><section id="method.try_from" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#812">source</a><a href="#method.try_from" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#tymethod.try_from" class="fn">try_from</a>(value: U) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <T as <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><U>>::<a class="associatedtype" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a>></h4></section></summary><div class='docblock'>Performs the conversion.</div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-TryInto%3CU%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#790-792">source</a><a href="#impl-TryInto%3CU%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T, U> <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryInto.html" title="trait core::convert::TryInto">TryInto</a><U> for T<div class="where">where
|
||
U: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>,</div></h3></section></summary><div class="impl-items"><details class="toggle" open><summary><section id="associatedtype.Error" class="associatedtype trait-impl"><a href="#associatedtype.Error" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/nightly/core/convert/trait.TryInto.html#associatedtype.Error" class="associatedtype">Error</a> = <U as <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>>::<a class="associatedtype" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a></h4></section></summary><div class='docblock'>The type returned in the event of a conversion error.</div></details><details class="toggle method-toggle" open><summary><section id="method.try_into" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#797">source</a><a href="#method.try_into" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/convert/trait.TryInto.html#tymethod.try_into" class="fn">try_into</a>(self) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><U, <U as <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>>::<a class="associatedtype" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a>></h4></section></summary><div class='docblock'>Performs the conversion.</div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-VZip%3CV%3E-for-T" class="impl"><a href="#impl-VZip%3CV%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<V, T> VZip<V> for T<div class="where">where
|
||
V: MultiLane<T>,</div></h3></section></summary><div class="impl-items"><section id="method.vzip" class="method trait-impl"><a href="#method.vzip" class="anchor">§</a><h4 class="code-header">fn <a class="fn">vzip</a>(self) -> V</h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-WithSubscriber-for-T" class="impl"><a href="#impl-WithSubscriber-for-T" class="anchor">§</a><h3 class="code-header">impl<T> WithSubscriber for T</h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.with_subscriber" class="method trait-impl"><a href="#method.with_subscriber" class="anchor">§</a><h4 class="code-header">fn <a class="fn">with_subscriber</a><S>(self, subscriber: S) -> WithDispatch<Self><div class="where">where
|
||
S: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><Dispatch>,</div></h4></section></summary><div class='docblock'>Attaches the provided <a href="super::Subscriber"><code>Subscriber</code></a> to this type, returning a
|
||
[<code>WithDispatch</code>] wrapper. <a>Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.with_current_subscriber" class="method trait-impl"><a href="#method.with_current_subscriber" class="anchor">§</a><h4 class="code-header">fn <a class="fn">with_current_subscriber</a>(self) -> WithDispatch<Self></h4></section></summary><div class='docblock'>Attaches the current <a href="crate::dispatcher#setting-the-default-subscriber">default</a> <a href="super::Subscriber"><code>Subscriber</code></a> to this type, returning a
|
||
[<code>WithDispatch</code>] wrapper. <a>Read more</a></div></details></div></details></div></section></div></main></body></html> |