89 lines
22 KiB
HTML
89 lines
22 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="Creates new `Service` values."><title>MakeService in tower - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2"href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../static.files/rustdoc-ca0dd0c4.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="tower" data-themes="" data-resource-suffix="" data-rustdoc-version="1.93.1 (01f6ddf75 2026-02-11) (Arch Linux rust 1:1.93.1-1)" data-channel="1.93.1" data-search-js="search-9e2438ea.js" data-stringdex-js="stringdex-a3946164.js" data-settings-js="settings-c38705f0.js" ><script src="../static.files/storage-e2aeef58.js"></script><script defer src="sidebar-items.js"></script><script defer src="../static.files/main-a410ff4d.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-263c88ec.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-eab170b8.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-044be391.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]--><rustdoc-topbar><h2><a href="#">MakeService</a></h2></rustdoc-topbar><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../tower/index.html">tower</a><span class="version">0.5.3</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Make<wbr>Service</a></h2><h3><a href="#required-associated-types">Required Associated Types</a></h3><ul class="block"><li><a href="#associatedtype.Error" title="Error">Error</a></li><li><a href="#associatedtype.Future" title="Future">Future</a></li><li><a href="#associatedtype.MakeError" title="MakeError">MakeError</a></li><li><a href="#associatedtype.Response" title="Response">Response</a></li><li><a href="#associatedtype.Service" title="Service">Service</a></li></ul><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.make_service" title="make_service">make_service</a></li><li><a href="#tymethod.poll_ready" title="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" title="as_service">as_service</a></li><li><a href="#method.into_service" title="into_service">into_service</a></li></ul><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="index.html">In crate tower</a></h2></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><section id="main-content" class="content"><div class="main-heading"><div class="rustdoc-breadcrumbs"><a href="index.html">tower</a></div><h1>Trait <span class="trait">Make<wbr>Service</span> <button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../src/tower/make/make_service.rs.html#21-130">Source</a> </span></div><pre class="rust item-decl"><code>pub trait MakeService<Target, Request>: Sealed<<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.tuple.html">(Target, Request)</a>> {
|
|
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><Request, Response = Self::<a class="associatedtype" href="trait.MakeService.html#associatedtype.Response" title="type tower::MakeService::Response">Response</a>, Error = Self::<a class="associatedtype" href="trait.MakeService.html#associatedtype.Error" title="type tower::MakeService::Error">Error</a>>;
|
|
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/1.93.1/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a><Output = <a class="enum" href="https://doc.rust-lang.org/1.93.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a><Self::<a class="associatedtype" href="trait.MakeService.html#associatedtype.Service" title="type tower::MakeService::Service">Service</a>, Self::<a class="associatedtype" href="trait.MakeService.html#associatedtype.MakeError" title="type tower::MakeService::MakeError">MakeError</a>>>;
|
|
|
|
// Required methods
|
|
fn <a href="#tymethod.poll_ready" class="fn">poll_ready</a>(
|
|
&mut self,
|
|
cx: &mut <a class="struct" href="https://doc.rust-lang.org/1.93.1/core/task/wake/struct.Context.html" title="struct core::task::wake::Context">Context</a><'_>,
|
|
) -> <a class="enum" href="https://doc.rust-lang.org/1.93.1/core/task/poll/enum.Poll.html" title="enum core::task::poll::Poll">Poll</a><<a class="enum" href="https://doc.rust-lang.org/1.93.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.unit.html">()</a>, Self::<a class="associatedtype" href="trait.MakeService.html#associatedtype.MakeError" title="type tower::MakeService::MakeError">MakeError</a>>>;
|
|
<span class="item-spacer"></span> fn <a href="#tymethod.make_service" class="fn">make_service</a>(&mut self, target: Target) -> Self::<a class="associatedtype" href="trait.MakeService.html#associatedtype.Future" title="type tower::MakeService::Future">Future</a>;
|
|
|
|
// Provided methods
|
|
fn <a href="#method.into_service" class="fn">into_service</a>(self) -> <a class="struct" href="make/struct.IntoService.html" title="struct tower::make::IntoService">IntoService</a><Self, Request>
|
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/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="fn">as_service</a>(&mut self) -> <a class="struct" href="make/struct.AsService.html" title="struct tower::make::AsService">AsService</a><'_, Self, Request>
|
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
|
|
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Creates new <a href="trait.Service.html" title="trait tower::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="trait tower::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="trait tower::Service"><code>Service</code></a> value using the
|
|
<a href="trait.MakeService.html" title="trait tower::MakeService"><code>MakeService</code></a> trait, and uses that new <a href="trait.Service.html" title="trait tower::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="trait tower::Service"><code>Service</code></a> of <a href="trait.Service.html" title="trait tower::Service"><code>Service</code></a>s.</p>
|
|
</div></details><h2 id="required-associated-types" class="section-header">Required Associated Types<a href="#required-associated-types" class="anchor">§</a></h2><div class="methods"><details class="toggle" open><summary><section id="associatedtype.Response" class="method"><a class="src 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="toggle" open><summary><section id="associatedtype.Error" class="method"><a class="src 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="toggle" open><summary><section id="associatedtype.Service" class="method"><a class="src 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><Request, Response = Self::<a class="associatedtype" href="trait.MakeService.html#associatedtype.Response" title="type tower::MakeService::Response">Response</a>, Error = Self::<a class="associatedtype" href="trait.MakeService.html#associatedtype.Error" title="type tower::MakeService::Error">Error</a>></h4></section></summary><div class="docblock"><p>The <a href="trait.Service.html" title="trait tower::Service"><code>Service</code></a> value created by this factory</p>
|
|
</div></details><details class="toggle" open><summary><section id="associatedtype.MakeError" class="method"><a class="src 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="toggle" open><summary><section id="associatedtype.Future" class="method"><a class="src 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/1.93.1/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a><Output = <a class="enum" href="https://doc.rust-lang.org/1.93.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a><Self::<a class="associatedtype" href="trait.MakeService.html#associatedtype.Service" title="type tower::MakeService::Service">Service</a>, Self::<a class="associatedtype" href="trait.MakeService.html#associatedtype.MakeError" title="type tower::MakeService::MakeError">MakeError</a>>></h4></section></summary><div class="docblock"><p>The future of the <a href="trait.Service.html" title="trait tower::Service"><code>Service</code></a> instance.</p>
|
|
</div></details></div><h2 id="required-methods" class="section-header">Required Methods<a href="#required-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="tymethod.poll_ready" class="method"><a class="src rightside" href="../src/tower/make/make_service.rs.html#45">Source</a><h4 class="code-header">fn <a href="#tymethod.poll_ready" class="fn">poll_ready</a>(
|
|
&mut self,
|
|
cx: &mut <a class="struct" href="https://doc.rust-lang.org/1.93.1/core/task/wake/struct.Context.html" title="struct core::task::wake::Context">Context</a><'_>,
|
|
) -> <a class="enum" href="https://doc.rust-lang.org/1.93.1/core/task/poll/enum.Poll.html" title="enum core::task::poll::Poll">Poll</a><<a class="enum" href="https://doc.rust-lang.org/1.93.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.unit.html">()</a>, Self::<a class="associatedtype" href="trait.MakeService.html#associatedtype.MakeError" title="type tower::MakeService::MakeError">MakeError</a>>></h4></section></summary><div class="docblock"><p>Returns <a href="https://doc.rust-lang.org/1.93.1/core/task/poll/enum.Poll.html#variant.Ready" title="variant core::task::poll::Poll::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/1.93.1/core/task/poll/enum.Poll.html#variant.Pending" title="variant core::task::poll::Poll::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="toggle method-toggle" open><summary><section id="tymethod.make_service" class="method"><a class="src rightside" href="../src/tower/make/make_service.rs.html#48">Source</a><h4 class="code-header">fn <a href="#tymethod.make_service" class="fn">make_service</a>(&mut self, target: Target) -> Self::<a class="associatedtype" href="trait.MakeService.html#associatedtype.Future" title="type tower::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="section-header">Provided Methods<a href="#provided-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="method.into_service" class="method"><a class="src rightside" href="../src/tower/make/make_service.rs.html#79-87">Source</a><h4 class="code-header">fn <a href="#method.into_service" class="fn">into_service</a>(self) -> <a class="struct" href="make/struct.IntoService.html" title="struct tower::make::IntoService">IntoService</a><Self, Request><div class="where">where
|
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><div class="docblock"><p>Consume this <a href="trait.MakeService.html" title="trait tower::MakeService"><code>MakeService</code></a> and convert it into a <a href="trait.Service.html" title="trait tower::Service"><code>Service</code></a>.</p>
|
|
<h5 id="example"><a class="doc-anchor" href="#example">§</a>Example</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>::<<span class="kw">_</span>, Infallible>(service_fn(|req: String| <span class="kw">async </span>{
|
|
<span class="prelude-val">Ok</span>::<<span class="kw">_</span>, Infallible>(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">"foo"</span>.to_string()).<span class="kw">await</span>.unwrap();</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.as_service" class="method"><a class="src rightside" href="../src/tower/make/make_service.rs.html#121-129">Source</a><h4 class="code-header">fn <a href="#method.as_service" class="fn">as_service</a>(&mut self) -> <a class="struct" href="make/struct.AsService.html" title="struct tower::make::AsService">AsService</a><'_, Self, Request><div class="where">where
|
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><div class="docblock"><p>Convert this <a href="trait.MakeService.html" title="trait tower::MakeService"><code>MakeService</code></a> into a <a href="trait.Service.html" title="trait tower::Service"><code>Service</code></a> without consuming the original <a href="trait.MakeService.html" title="trait tower::MakeService"><code>MakeService</code></a>.</p>
|
|
<h5 id="example-1"><a class="doc-anchor" href="#example-1">§</a>Example</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>::<<span class="kw">_</span>, Infallible>(service_fn(|req: String| <span class="kw">async </span>{
|
|
<span class="prelude-val">Ok</span>::<<span class="kw">_</span>, Infallible>(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">"foo"</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="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"><details class="toggle implementors-toggle"><summary><section id="impl-MakeService%3CTarget,+Request%3E-for-M" class="impl"><a class="src rightside" href="../src/tower/make/make_service.rs.html#139-157">Source</a><a href="#impl-MakeService%3CTarget,+Request%3E-for-M" class="anchor">§</a><h3 class="code-header">impl<M, S, Target, Request> <a class="trait" href="trait.MakeService.html" title="trait tower::MakeService">MakeService</a><Target, Request> for M<div class="where">where
|
|
M: <a class="trait" href="trait.Service.html" title="trait tower::Service">Service</a><Target, Response = S>,
|
|
S: <a class="trait" href="trait.Service.html" title="trait tower::Service">Service</a><Request>,</div></h3></section></summary><div class="impl-items"><section id="associatedtype.Response-1" class="associatedtype trait-impl"><a class="src rightside" href="../src/tower/make/make_service.rs.html#144">Source</a><a href="#associatedtype.Response-1" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.Response" class="associatedtype">Response</a> = <S as <a class="trait" href="trait.Service.html" title="trait tower::Service">Service</a><Request>>::<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"><a class="src rightside" href="../src/tower/make/make_service.rs.html#145">Source</a><a href="#associatedtype.Error-1" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.Error" class="associatedtype">Error</a> = <S as <a class="trait" href="trait.Service.html" title="trait tower::Service">Service</a><Request>>::<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"><a class="src rightside" href="../src/tower/make/make_service.rs.html#146">Source</a><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"><a class="src rightside" href="../src/tower/make/make_service.rs.html#147">Source</a><a href="#associatedtype.MakeError-1" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.MakeError" class="associatedtype">MakeError</a> = <M as <a class="trait" href="trait.Service.html" title="trait tower::Service">Service</a><Target>>::<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"><a class="src rightside" href="../src/tower/make/make_service.rs.html#148">Source</a><a href="#associatedtype.Future-1" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.Future" class="associatedtype">Future</a> = <M as <a class="trait" href="trait.Service.html" title="trait tower::Service">Service</a><Target>>::<a class="associatedtype" href="trait.Service.html#associatedtype.Future" title="type tower::Service::Future">Future</a></h4></section></div></details></div><script src="../trait.impl/tower/make/make_service/trait.MakeService.js" async></script></section></div></main></body></html> |