38 lines
6.3 KiB
HTML
38 lines
6.3 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="API documentation for the Rust `service` mod in crate `hyper`."><meta name="keywords" content="rust, rustlang, rust-lang, service"><title>hyper::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="../../light.css" id="themeStyle"><link rel="stylesheet" type="text/css" href="../../dark.css" disabled ><link rel="stylesheet" type="text/css" href="../../ayu.css" disabled ><script id="default-settings"></script><script src="../../storage.js"></script><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="icon" type="image/svg+xml" href="../../favicon.svg">
|
||
<link rel="alternate icon" type="image/png" href="../../favicon-16x16.png">
|
||
<link rel="alternate icon" type="image/png" href="../../favicon-32x32.png"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc mod"><!--[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">☰</div><a href='../../hyper/index.html'><div class='logo-container rust-logo'><img src='../../rust-logo.png' alt='logo'></div></a><p class="location">Module service</p><div class="sidebar-elems"><div class="block items"><ul><li><a href="#traits">Traits</a></li><li><a href="#functions">Functions</a></li></ul></div><p class="location"><a href="../index.html">hyper</a></p><script>window.sidebarCurrent = {name: "service", ty: "mod", relpath: "../"};</script><script defer src="../sidebar-items.js"></script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu"><img src="../../brush.svg" width="18" alt="Pick another theme!"></button><div id="theme-choices" role="menu"></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><button type="button" class="help-button">?</button>
|
||
<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">−</span>]</a></span><a class="srclink" href="../../src/hyper/service/mod.rs.html#1-55" title="goto source code">[src]</a></span><span class="in-band">Module <a href="../index.html">hyper</a>::<wbr><a class="mod" href="">service</a></span></h1><div class="docblock"><p>Asynchronous Services</p>
|
||
<p>A <a href="../../hyper/service/trait.Service.html"><code>Service</code></a> is a trait representing an asynchronous
|
||
function of a request to a response. It's similar to
|
||
<code>async fn(Request) -> Result<Response, Error></code>.</p>
|
||
<p>The argument and return value isn't strictly required to be for HTTP.
|
||
Therefore, hyper uses several "trait aliases" to reduce clutter around
|
||
bounds. These are:</p>
|
||
<ul>
|
||
<li><code>HttpService</code>: This is blanketly implemented for all types that
|
||
implement <code>Service<http::Request<B1>, Response = http::Response<B2>></code>.</li>
|
||
<li><code>MakeService</code>: When a <code>Service</code> returns a new <code>Service</code> as its "response",
|
||
we consider it a <code>MakeService</code>. Again, blanketly implemented in those cases.</li>
|
||
<li><code>MakeConnection</code>: A <code>Service</code> that returns a "connection", a type that
|
||
implements <code>AsyncRead</code> and <code>AsyncWrite</code>.</li>
|
||
</ul>
|
||
<h1 id="httpservice" class="section-header"><a href="#httpservice">HttpService</a></h1>
|
||
<p>In hyper, especially in the server setting, a <code>Service</code> is usually bound
|
||
to a single connection. It defines how to respond to <strong>all</strong> requests that
|
||
connection will receive.</p>
|
||
<p>The helper <a href="../../hyper/service/fn.service_fn.html"><code>service_fn</code></a> should be sufficient for most cases, but
|
||
if you need to implement <code>Service</code> for a type manually, you can follow the example
|
||
in <code>service_struct_impl.rs</code>.</p>
|
||
<h1 id="makeservice" class="section-header"><a href="#makeservice">MakeService</a></h1>
|
||
<p>Since a <code>Service</code> is bound to a single connection, a <a href="crate::Server"><code>Server</code></a>
|
||
needs a way to make them as it accepts connections. This is what a
|
||
<code>MakeService</code> does.</p>
|
||
<p>Resources that need to be shared by all <code>Service</code>s can be put into a
|
||
<code>MakeService</code>, and then passed to individual <code>Service</code>s when <code>call</code>
|
||
is called.</p>
|
||
</div><h2 id="traits" class="section-header"><a href="#traits">Traits</a></h2>
|
||
<table><tr class="module-item"><td><a class="trait" href="trait.Service.html" title="hyper::service::Service trait">Service</a></td><td class="docblock-short"><p>An asynchronous function from a <code>Request</code> to a <code>Response</code>.</p>
|
||
</td></tr></table><h2 id="functions" class="section-header"><a href="#functions">Functions</a></h2>
|
||
<table><tr class="module-item"><td><a class="fn" href="fn.make_service_fn.html" title="hyper::service::make_service_fn fn">make_service_fn</a></td><td class="docblock-short"><p>Create a <code>MakeService</code> from a function.</p>
|
||
</td></tr><tr class="module-item"><td><a class="fn" href="fn.service_fn.html" title="hyper::service::service_fn fn">service_fn</a></td><td class="docblock-short"><p>Create a <code>Service</code> from a function.</p>
|
||
</td></tr></table></section><section id="search" class="content hidden"></section><section class="footer"></section><script>window.rootPath = "../../";window.currentCrate = "hyper";</script><script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html> |