Files
mercator_service/actix_web/test/fn.init_service.html

22 lines
6.8 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!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="API documentation for the Rust `init_service` fn in crate `actix_web`."><meta name="keywords" content="rust, rustlang, rust-lang, init_service"><title>actix_web::test::init_service - Rust</title><link rel="stylesheet" type="text/css" href="../../normalize.css"><link rel="stylesheet" type="text/css" href="../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../../dark.css"><link rel="stylesheet" type="text/css" href="../../light.css" id="themeStyle"><script src="../../storage.js"></script><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="shortcut icon" href="../../favicon.ico"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc fn"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu">&#9776;</div><a href='../../actix_web/index.html'><div class='logo-container'><img src='../../rust-logo.png' alt='logo'></div></a><div class="sidebar-elems"><p class='location'><a href='../index.html'>actix_web</a>::<wbr><a href='index.html'>test</a></p><script>window.sidebarCurrent = {name: 'init_service', ty: 'fn', relpath: ''};</script><script defer src="sidebar-items.js"></script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!"><img src="../../brush.svg" width="18" alt="Pick another theme!"></button><div id="theme-choices"></div></div><script src="../../theme.js"></script><nav class="sub"><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" disabled autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"></div><a id="settings-menu" href="../../settings.html"><img src="../../wheel.svg" width="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class='fqn'><span class='out-of-band'><span id='render-detail'><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class='inner'>&#x2212;</span>]</a></span><a class='srclink' href='../../src/actix_web/test.rs.html#69-86' title='goto source code'>[src]</a></span><span class='in-band'>Function <a href='../index.html'>actix_web</a>::<wbr><a href='index.html'>test</a>::<wbr><a class="fn" href=''>init_service</a></span></h1><pre class='rust fn'>pub fn init_service&lt;R, S, B, E&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;app: R<br>) -&gt; impl <a class="trait" href="../../actix_web/dev/trait.Service.html" title="trait actix_web::dev::Service">Service</a>&lt;Request = <a class="struct" href="../../actix_http/request/struct.Request.html" title="struct actix_http::request::Request">Request</a>, Response = <a class="struct" href="../../actix_web/dev/struct.ServiceResponse.html" title="struct actix_web::dev::ServiceResponse">ServiceResponse</a>&lt;B&gt;, Error = E&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;R: <a class="trait" href="../../actix_service/trait.IntoNewService.html" title="trait actix_service::IntoNewService">IntoNewService</a>&lt;S&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;S: <a class="trait" href="../../actix_service/trait.NewService.html" title="trait actix_service::NewService">NewService</a>&lt;Config = <a class="struct" href="../../actix_server_config/struct.ServerConfig.html" title="struct actix_server_config::ServerConfig">ServerConfig</a>, Request = <a class="struct" href="../../actix_http/request/struct.Request.html" title="struct actix_http::request::Request">Request</a>, Response = <a class="struct" href="../../actix_web/dev/struct.ServiceResponse.html" title="struct actix_web::dev::ServiceResponse">ServiceResponse</a>&lt;B&gt;, Error = E&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;S::<a class="type" href="../../actix_service/trait.NewService.html#associatedtype.InitError" title="type actix_service::NewService::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>,&nbsp;</span></pre><div class='docblock'><p>This method accepts application builder instance, and constructs
service.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">actix_service</span>::<span class="ident">Service</span>;
<span class="kw">use</span> <span class="ident">actix_web</span>::{<span class="ident">test</span>, <span class="ident">web</span>, <span class="ident">App</span>, <span class="ident">HttpResponse</span>, <span class="ident">http</span>::<span class="ident">StatusCode</span>};
<span class="attribute">#[<span class="ident">test</span>]</span>
<span class="kw">fn</span> <span class="ident">test_init_service</span>() {
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">app</span> <span class="op">=</span> <span class="ident">test</span>::<span class="ident">init_service</span>(
<span class="ident">App</span>::<span class="ident">new</span>()
.<span class="ident">service</span>(<span class="ident">web</span>::<span class="ident">resource</span>(<span class="string">&quot;/test&quot;</span>).<span class="ident">to</span>(<span class="op">|</span><span class="op">|</span> <span class="ident">HttpResponse</span>::<span class="prelude-val">Ok</span>()))
);
<span class="comment">// Create request object</span>
<span class="kw">let</span> <span class="ident">req</span> <span class="op">=</span> <span class="ident">test</span>::<span class="ident">TestRequest</span>::<span class="ident">with_uri</span>(<span class="string">&quot;/test&quot;</span>).<span class="ident">to_request</span>();
<span class="comment">// Execute application</span>
<span class="kw">let</span> <span class="ident">resp</span> <span class="op">=</span> <span class="ident">test</span>::<span class="ident">block_on</span>(<span class="ident">app</span>.<span class="ident">call</span>(<span class="ident">req</span>)).<span class="ident">unwrap</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">resp</span>.<span class="ident">status</span>(), <span class="ident">StatusCode</span>::<span class="ident">OK</span>);
}</pre></div>
</div></section><section id="search" class="content hidden"></section><section class="footer"></section><script>window.rootPath = "../../";window.currentCrate = "actix_web";</script><script src="../../aliases.js"></script><script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>