blob: d12c95b0b5b82cadc9c3b0d3f08dd7525cfed3c3 [file] [log] [blame]
<!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="Creates new [`Service`] values."><meta name="keywords" content="rust, rustlang, rust-lang, MakeService"><title>MakeService in tower::make - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" href="../../normalize.css"><link rel="stylesheet" href="../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" href="../../ayu.css" disabled><link rel="stylesheet" href="../../dark.css" disabled><link rel="stylesheet" href="../../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../../storage.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../main.js"></script><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../../favicon.svg"></head><body class="rustdoc trait"><!--[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">&#9776;</button><a class="sidebar-logo" href="../../tower/index.html"><div class="logo-container"><img class="rust-logo" src="../../rust-logo.svg" alt="logo"></div></a><h2></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../../tower/index.html"><div class="logo-container"><img class="rust-logo" src="../../rust-logo.svg" alt="logo"></div></a><h2 class="location"><a href="#">MakeService</a></h2><div class="sidebar-elems"><section><h3><a href="#required-associated-types">Required Associated Types</a></h3><ul class="block"><li><a href="#associatedtype.Error">Error</a></li><li><a href="#associatedtype.Future">Future</a></li><li><a href="#associatedtype.MakeError">MakeError</a></li><li><a href="#associatedtype.Response">Response</a></li><li><a href="#associatedtype.Service">Service</a></li></ul><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.make_service">make_service</a></li><li><a href="#tymethod.poll_ready">poll_ready</a></li></ul><h3><a href="#provided-methods">Provided Methods</a></h3><ul class="block"><li><a href="#method.as_service">as_service</a></li><li><a href="#method.into_service">into_service</a></li></ul><h3><a href="#implementors">Implementors</a></h3></section><h2><a href="index.html">In tower::make</a></h2></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../wheel.svg"></a></div></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1 class="fqn">Trait <a href="../index.html">tower</a>::<wbr><a href="index.html">make</a>::<wbr><a class="trait" href="#">MakeService</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../../clipboard.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="srclink" href="../../src/tower/make/make_service.rs.html#21-130">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span></div><div class="item-decl"><pre class="rust trait"><code>pub trait MakeService&lt;Target, Request&gt;: Sealed&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">(Target, Request)</a>&gt; {
type <a href="#associatedtype.Response" class="associatedtype">Response</a>;
type <a href="#associatedtype.Error" class="associatedtype">Error</a>;
type <a href="#associatedtype.Service" class="associatedtype">Service</a>: <a class="trait" href="../trait.Service.html" title="trait tower::Service">Service</a>&lt;Request, Response = Self::<a class="associatedtype" href="trait.MakeService.html#associatedtype.Response" title="type tower::make::MakeService::Response">Response</a>, Error = Self::<a class="associatedtype" href="trait.MakeService.html#associatedtype.Error" title="type tower::make::MakeService::Error">Error</a>&gt;;
type <a href="#associatedtype.MakeError" class="associatedtype">MakeError</a>;
type <a href="#associatedtype.Future" class="associatedtype">Future</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>&lt;Output = <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;Self::<a class="associatedtype" href="trait.MakeService.html#associatedtype.Service" title="type tower::make::MakeService::Service">Service</a>, Self::<a class="associatedtype" href="trait.MakeService.html#associatedtype.MakeError" title="type tower::make::MakeService::MakeError">MakeError</a>&gt;&gt;;
fn <a href="#tymethod.poll_ready" class="fnname">poll_ready</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;mut self,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cx: &amp;mut <a class="struct" href="https://doc.rust-lang.org/nightly/core/task/wake/struct.Context.html" title="struct core::task::wake::Context">Context</a>&lt;'_&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/task/poll/enum.Poll.html" title="enum core::task::poll::Poll">Poll</a>&lt;<a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Self::<a class="associatedtype" href="trait.MakeService.html#associatedtype.MakeError" title="type tower::make::MakeService::MakeError">MakeError</a>&gt;&gt;;
<span class="item-spacer"></span> fn <a href="#tymethod.make_service" class="fnname">make_service</a>(&amp;mut self, target: Target) -&gt; Self::<a class="associatedtype" href="trait.MakeService.html#associatedtype.Future" title="type tower::make::MakeService::Future">Future</a>;
fn <a href="#method.into_service" class="fnname">into_service</a>(self) -&gt; <a class="struct" href="struct.IntoService.html" title="struct tower::make::IntoService">IntoService</a>&lt;Self, Request&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="where">where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span>,
{ ... }
<span class="item-spacer"></span> fn <a href="#method.as_service" class="fnname">as_service</a>(&amp;mut self) -&gt; <a class="struct" href="struct.AsService.html" title="struct tower::make::AsService">AsService</a>&lt;'_, Self, Request&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="where">where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span>,
{ ... }
}</code></pre></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Creates new <a href="../trait.Service.html" title="Service"><code>Service</code></a> values.</p>
<p>Acts as a service factory. This is useful for cases where new <a href="../trait.Service.html" title="Service"><code>Service</code></a>
values must be produced. One case is a TCP server listener. The listener
accepts new TCP streams, obtains a new <a href="../trait.Service.html" title="Service"><code>Service</code></a> value using the
<a href="trait.MakeService.html" title="MakeService"><code>MakeService</code></a> trait, and uses that new <a href="../trait.Service.html" title="Service"><code>Service</code></a> value to process inbound
requests on that new TCP stream.</p>
<p>This is essentially a trait alias for a <a href="../trait.Service.html" title="Service"><code>Service</code></a> of <a href="../trait.Service.html" title="Service"><code>Service</code></a>s.</p>
</div></details><h2 id="required-associated-types" class="small-section-header">Required Associated Types<a href="#required-associated-types" class="anchor"></a></h2><div class="methods"><details class="rustdoc-toggle method-toggle" open><summary><section id="associatedtype.Response" class="method has-srclink"><a class="srclink rightside" href="../../src/tower/make/make_service.rs.html#23">source</a><h4 class="code-header">type <a href="#associatedtype.Response" class="associatedtype">Response</a></h4></section></summary><div class="docblock"><p>Responses given by the service</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="associatedtype.Error" class="method has-srclink"><a class="srclink rightside" href="../../src/tower/make/make_service.rs.html#26">source</a><h4 class="code-header">type <a href="#associatedtype.Error" class="associatedtype">Error</a></h4></section></summary><div class="docblock"><p>Errors produced by the service</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="associatedtype.Service" class="method has-srclink"><a class="srclink rightside" href="../../src/tower/make/make_service.rs.html#29">source</a><h4 class="code-header">type <a href="#associatedtype.Service" class="associatedtype">Service</a>: <a class="trait" href="../trait.Service.html" title="trait tower::Service">Service</a>&lt;Request, Response = Self::<a class="associatedtype" href="trait.MakeService.html#associatedtype.Response" title="type tower::make::MakeService::Response">Response</a>, Error = Self::<a class="associatedtype" href="trait.MakeService.html#associatedtype.Error" title="type tower::make::MakeService::Error">Error</a>&gt;</h4></section></summary><div class="docblock"><p>The <a href="../trait.Service.html" title="Service"><code>Service</code></a> value created by this factory</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="associatedtype.MakeError" class="method has-srclink"><a class="srclink rightside" href="../../src/tower/make/make_service.rs.html#32">source</a><h4 class="code-header">type <a href="#associatedtype.MakeError" class="associatedtype">MakeError</a></h4></section></summary><div class="docblock"><p>Errors produced while building a service.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="associatedtype.Future" class="method has-srclink"><a class="srclink rightside" href="../../src/tower/make/make_service.rs.html#35">source</a><h4 class="code-header">type <a href="#associatedtype.Future" class="associatedtype">Future</a>: <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>&lt;Output = <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;Self::<a class="associatedtype" href="trait.MakeService.html#associatedtype.Service" title="type tower::make::MakeService::Service">Service</a>, Self::<a class="associatedtype" href="trait.MakeService.html#associatedtype.MakeError" title="type tower::make::MakeService::MakeError">MakeError</a>&gt;&gt;</h4></section></summary><div class="docblock"><p>The future of the <a href="../trait.Service.html" title="Service"><code>Service</code></a> instance.</p>
</div></details></div><h2 id="required-methods" class="small-section-header">Required Methods<a href="#required-methods" class="anchor"></a></h2><div class="methods"><details class="rustdoc-toggle method-toggle" open><summary><section id="tymethod.poll_ready" class="method has-srclink"><a class="srclink rightside" href="../../src/tower/make/make_service.rs.html#45">source</a><h4 class="code-header">fn <a href="#tymethod.poll_ready" class="fnname">poll_ready</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;mut self,<br>&nbsp;&nbsp;&nbsp;&nbsp;cx: &amp;mut <a class="struct" href="https://doc.rust-lang.org/nightly/core/task/wake/struct.Context.html" title="struct core::task::wake::Context">Context</a>&lt;'_&gt;<br>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/task/poll/enum.Poll.html" title="enum core::task::poll::Poll">Poll</a>&lt;<a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, Self::<a class="associatedtype" href="trait.MakeService.html#associatedtype.MakeError" title="type tower::make::MakeService::MakeError">MakeError</a>&gt;&gt;</h4></section></summary><div class="docblock"><p>Returns <a href="https://doc.rust-lang.org/nightly/core/task/poll/enum.Poll.html#variant.Ready"><code>Poll::Ready</code></a> when the factory is able to create more services.</p>
<p>If the service is at capacity, then <a href="https://doc.rust-lang.org/nightly/core/task/poll/enum.Poll.html#variant.Pending"><code>Poll::Pending</code></a> is returned and the task
is notified when the service becomes ready again. This function is
expected to be called while on a task.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="tymethod.make_service" class="method has-srclink"><a class="srclink rightside" href="../../src/tower/make/make_service.rs.html#48">source</a><h4 class="code-header">fn <a href="#tymethod.make_service" class="fnname">make_service</a>(&amp;mut self, target: Target) -&gt; Self::<a class="associatedtype" href="trait.MakeService.html#associatedtype.Future" title="type tower::make::MakeService::Future">Future</a></h4></section></summary><div class="docblock"><p>Create and return a new service value asynchronously.</p>
</div></details></div><h2 id="provided-methods" class="small-section-header">Provided Methods<a href="#provided-methods" class="anchor"></a></h2><div class="methods"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.into_service" class="method has-srclink"><a class="srclink rightside" href="../../src/tower/make/make_service.rs.html#79-87">source</a><h4 class="code-header">fn <a href="#method.into_service" class="fnname">into_service</a>(self) -&gt; <a class="struct" href="struct.IntoService.html" title="struct tower::make::IntoService">IntoService</a>&lt;Self, Request&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</span></h4></section></summary><div class="docblock"><p>Consume this <a href="trait.MakeService.html" title="MakeService"><code>MakeService</code></a> and convert it into a <a href="../trait.Service.html" title="Service"><code>Service</code></a>.</p>
<h5 id="example"><a href="#example">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::convert::Infallible;
<span class="kw">use </span>tower::Service;
<span class="kw">use </span>tower::make::MakeService;
<span class="kw">use </span>tower::service_fn;
<span class="comment">// A `MakeService`
</span><span class="kw">let </span>make_service = service_fn(|make_req: ()| <span class="kw">async </span>{
<span class="prelude-val">Ok</span>::&lt;<span class="kw">_</span>, Infallible&gt;(service_fn(|req: String| <span class="kw">async </span>{
<span class="prelude-val">Ok</span>::&lt;<span class="kw">_</span>, Infallible&gt;(req)
}))
});
<span class="comment">// Convert the `MakeService` into a `Service`
</span><span class="kw">let </span><span class="kw-2">mut </span>svc = make_service.into_service();
<span class="comment">// Make a new service
</span><span class="kw">let </span><span class="kw-2">mut </span>new_svc = svc.call(()).<span class="kw">await</span>.unwrap();
<span class="comment">// Call the service
</span><span class="kw">let </span>res = new_svc.call(<span class="string">&quot;foo&quot;</span>.to_string()).<span class="kw">await</span>.unwrap();</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.as_service" class="method has-srclink"><a class="srclink rightside" href="../../src/tower/make/make_service.rs.html#121-129">source</a><h4 class="code-header">fn <a href="#method.as_service" class="fnname">as_service</a>(&amp;mut self) -&gt; <a class="struct" href="struct.AsService.html" title="struct tower::make::AsService">AsService</a>&lt;'_, Self, Request&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</span></h4></section></summary><div class="docblock"><p>Convert this <a href="trait.MakeService.html" title="MakeService"><code>MakeService</code></a> into a <a href="../trait.Service.html" title="Service"><code>Service</code></a> without consuming the original <a href="trait.MakeService.html" title="MakeService"><code>MakeService</code></a>.</p>
<h5 id="example-1"><a href="#example-1">Example</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::convert::Infallible;
<span class="kw">use </span>tower::Service;
<span class="kw">use </span>tower::make::MakeService;
<span class="kw">use </span>tower::service_fn;
<span class="comment">// A `MakeService`
</span><span class="kw">let </span><span class="kw-2">mut </span>make_service = service_fn(|make_req: ()| <span class="kw">async </span>{
<span class="prelude-val">Ok</span>::&lt;<span class="kw">_</span>, Infallible&gt;(service_fn(|req: String| <span class="kw">async </span>{
<span class="prelude-val">Ok</span>::&lt;<span class="kw">_</span>, Infallible&gt;(req)
}))
});
<span class="comment">// Convert the `MakeService` into a `Service`
</span><span class="kw">let </span><span class="kw-2">mut </span>svc = make_service.as_service();
<span class="comment">// Make a new service
</span><span class="kw">let </span><span class="kw-2">mut </span>new_svc = svc.call(()).<span class="kw">await</span>.unwrap();
<span class="comment">// Call the service
</span><span class="kw">let </span>res = new_svc.call(<span class="string">&quot;foo&quot;</span>.to_string()).<span class="kw">await</span>.unwrap();
<span class="comment">// The original `MakeService` is still accessible
</span><span class="kw">let </span>new_svc = make_service.make_service(()).<span class="kw">await</span>.unwrap();</code></pre></div>
</div></details></div><h2 id="implementors" class="small-section-header">Implementors<a href="#implementors" class="anchor"></a></h2><div id="implementors-list"><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-MakeService%3CTarget%2C%20Request%3E-for-M" class="impl has-srclink"><a class="srclink rightside" href="../../src/tower/make/make_service.rs.html#139-157">source</a><a href="#impl-MakeService%3CTarget%2C%20Request%3E-for-M" class="anchor"></a><h3 class="code-header">impl&lt;M, S, Target, Request&gt; <a class="trait" href="trait.MakeService.html" title="trait tower::make::MakeService">MakeService</a>&lt;Target, Request&gt; for M<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;M: <a class="trait" href="../trait.Service.html" title="trait tower::Service">Service</a>&lt;Target, Response = S&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;S: <a class="trait" href="../trait.Service.html" title="trait tower::Service">Service</a>&lt;Request&gt;,</span></h3></section></summary><div class="impl-items"><section id="associatedtype.Response-1" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Response-1" class="anchor"></a><h4 class="code-header">type <a href="#associatedtype.Response" class="associatedtype">Response</a> = &lt;S as <a class="trait" href="../trait.Service.html" title="trait tower::Service">Service</a>&lt;Request&gt;&gt;::<a class="associatedtype" href="../trait.Service.html#associatedtype.Response" title="type tower::Service::Response">Response</a></h4></section><section id="associatedtype.Error-1" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Error-1" class="anchor"></a><h4 class="code-header">type <a href="#associatedtype.Error" class="associatedtype">Error</a> = &lt;S as <a class="trait" href="../trait.Service.html" title="trait tower::Service">Service</a>&lt;Request&gt;&gt;::<a class="associatedtype" href="../trait.Service.html#associatedtype.Error" title="type tower::Service::Error">Error</a></h4></section><section id="associatedtype.Service-1" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Service-1" class="anchor"></a><h4 class="code-header">type <a href="#associatedtype.Service" class="associatedtype">Service</a> = S</h4></section><section id="associatedtype.MakeError-1" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.MakeError-1" class="anchor"></a><h4 class="code-header">type <a href="#associatedtype.MakeError" class="associatedtype">MakeError</a> = &lt;M as <a class="trait" href="../trait.Service.html" title="trait tower::Service">Service</a>&lt;Target&gt;&gt;::<a class="associatedtype" href="../trait.Service.html#associatedtype.Error" title="type tower::Service::Error">Error</a></h4></section><section id="associatedtype.Future-1" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Future-1" class="anchor"></a><h4 class="code-header">type <a href="#associatedtype.Future" class="associatedtype">Future</a> = &lt;M as <a class="trait" href="../trait.Service.html" title="trait tower::Service">Service</a>&lt;Target&gt;&gt;::<a class="associatedtype" href="../trait.Service.html#associatedtype.Future" title="type tower::Service::Future">Future</a></h4></section></div></details></div><script src="../../implementors/tower/make/make_service/trait.MakeService.js" async></script></section></div></main><div id="rustdoc-vars" data-root-path="../../" data-current-crate="tower" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.66.0-nightly (5c8bff74b 2022-10-21)" ></div></body></html>