Initial docs commit

This commit is contained in:
Uttarayan Mondal
2021-03-15 01:27:34 +05:30
commit d5ecda4c73
20211 changed files with 1370362 additions and 0 deletions
@@ -0,0 +1,34 @@
<!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="Create a `MakeService` from a function."><meta name="keywords" content="rust, rustlang, rust-lang, make_service_fn"><title>hyper::service::make_service_fn - 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 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='../../hyper/index.html'><div class='logo-container rust-logo'><img src='../../rust-logo.png' alt='logo'></div></a><div class="sidebar-elems"><p class="location"><a href="../index.html">hyper</a>::<wbr><a href="index.html">service</a></p><div id="sidebar-vars" data-name="make_service_fn" data-ty="fn" data-relpath=""></div><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="in-band">Function <a href="../index.html">hyper</a>::<wbr><a href="index.html">service</a>::<wbr><a class="fn" href="">make_service_fn</a></span><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/hyper/service/make.rs.html#138-144" title="goto source code">[src]</a></span></h1><pre class="rust fn">pub fn make_service_fn&lt;F, Target, Ret&gt;(f: F) -&gt; MakeServiceFn&lt;F&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;</a>Target) -&gt; Ret,<br>&nbsp;&nbsp;&nbsp;&nbsp;Ret: <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>,&nbsp;</span></pre><div class="docblock"><p>Create a <code>MakeService</code> from a function.</p>
<h1 id="example" class="section-header"><a href="#example">Example</a></h1>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">convert</span>::<span class="ident">Infallible</span>;
<span class="kw">use</span> <span class="ident">hyper</span>::{<span class="ident">Body</span>, <span class="ident">Request</span>, <span class="ident">Response</span>, <span class="ident">Server</span>};
<span class="kw">use</span> <span class="ident">hyper</span>::<span class="ident">server</span>::<span class="ident">conn</span>::<span class="ident">AddrStream</span>;
<span class="kw">use</span> <span class="ident">hyper</span>::<span class="ident">service</span>::{<span class="ident">make_service_fn</span>, <span class="ident">service_fn</span>};
<span class="kw">let</span> <span class="ident">addr</span> <span class="op">=</span> ([<span class="number">127</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">1</span>], <span class="number">3000</span>).<span class="ident">into</span>();
<span class="kw">let</span> <span class="ident">make_svc</span> <span class="op">=</span> <span class="ident">make_service_fn</span>(<span class="op">|</span><span class="ident">socket</span>: <span class="kw-2">&amp;</span><span class="ident">AddrStream</span><span class="op">|</span> {
<span class="kw">let</span> <span class="ident">remote_addr</span> <span class="op">=</span> <span class="ident">socket</span>.<span class="ident">remote_addr</span>();
<span class="kw">async</span> <span class="kw">move</span> {
<span class="prelude-val">Ok</span>::<span class="op">&lt;</span><span class="kw">_</span>, <span class="ident">Infallible</span><span class="op">&gt;</span>(<span class="ident">service_fn</span>(<span class="kw">move</span> <span class="op">|</span><span class="kw">_</span>: <span class="ident">Request</span><span class="op">&lt;</span><span class="ident">Body</span><span class="op">&gt;</span><span class="op">|</span> <span class="kw">async</span> <span class="kw">move</span> {
<span class="prelude-val">Ok</span>::<span class="op">&lt;</span><span class="kw">_</span>, <span class="ident">Infallible</span><span class="op">&gt;</span>(
<span class="ident">Response</span>::<span class="ident">new</span>(<span class="ident">Body</span>::<span class="ident">from</span>(<span class="macro">format</span><span class="macro">!</span>(<span class="string">&quot;Hello, {}!&quot;</span>, <span class="ident">remote_addr</span>)))
)
}))
}
});
<span class="comment">// Then bind and serve...</span>
<span class="kw">let</span> <span class="ident">server</span> <span class="op">=</span> <span class="ident">Server</span>::<span class="ident">bind</span>(<span class="kw-2">&amp;</span><span class="ident">addr</span>)
.<span class="ident">serve</span>(<span class="ident">make_svc</span>);
<span class="comment">// Finally, spawn `server` onto an Executor...</span>
<span class="kw">if</span> <span class="kw">let</span> <span class="prelude-val">Err</span>(<span class="ident">e</span>) <span class="op">=</span> <span class="ident">server</span>.<span class="kw">await</span> {
<span class="macro">eprintln</span><span class="macro">!</span>(<span class="string">&quot;server error: {}&quot;</span>, <span class="ident">e</span>);
}</pre></div>
</div></section><section id="search" class="content hidden"></section><section class="footer"></section><div id="rustdoc-vars" data-root-path="../../" data-current-crate="hyper"></div>
<script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>
+20
View File
@@ -0,0 +1,20 @@
<!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="Create a `Service` from a function."><meta name="keywords" content="rust, rustlang, rust-lang, service_fn"><title>hyper::service::service_fn - 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 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='../../hyper/index.html'><div class='logo-container rust-logo'><img src='../../rust-logo.png' alt='logo'></div></a><div class="sidebar-elems"><p class="location"><a href="../index.html">hyper</a>::<wbr><a href="index.html">service</a></p><div id="sidebar-vars" data-name="service_fn" data-ty="fn" data-relpath=""></div><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="in-band">Function <a href="../index.html">hyper</a>::<wbr><a href="index.html">service</a>::<wbr><a class="fn" href="">service_fn</a></span><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/hyper/service/util.rs.html#27-36" title="goto source code">[src]</a></span></h1><pre class="rust fn">pub fn service_fn&lt;F, R, S&gt;(f: F) -&gt; ServiceFn&lt;F, R&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="struct" href="../../hyper/struct.Request.html" title="struct hyper::Request">Request</a>&lt;R&gt;) -&gt; S,<br>&nbsp;&nbsp;&nbsp;&nbsp;S: <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a>,&nbsp;</span></pre><div class="docblock"><p>Create a <code>Service</code> from a function.</p>
<h1 id="example" class="section-header"><a href="#example">Example</a></h1>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">hyper</span>::{<span class="ident">Body</span>, <span class="ident">Request</span>, <span class="ident">Response</span>, <span class="ident">Version</span>};
<span class="kw">use</span> <span class="ident">hyper</span>::<span class="ident">service</span>::<span class="ident">service_fn</span>;
<span class="kw">let</span> <span class="ident">service</span> <span class="op">=</span> <span class="ident">service_fn</span>(<span class="op">|</span><span class="ident">req</span>: <span class="ident">Request</span><span class="op">&lt;</span><span class="ident">Body</span><span class="op">&gt;</span><span class="op">|</span> <span class="kw">async</span> <span class="kw">move</span> {
<span class="kw">if</span> <span class="ident">req</span>.<span class="ident">version</span>() <span class="op">=</span><span class="op">=</span> <span class="ident">Version</span>::<span class="ident">HTTP_11</span> {
<span class="prelude-val">Ok</span>(<span class="ident">Response</span>::<span class="ident">new</span>(<span class="ident">Body</span>::<span class="ident">from</span>(<span class="string">&quot;Hello World&quot;</span>)))
} <span class="kw">else</span> {
<span class="comment">// Note: it&#39;s usually better to return a Response</span>
<span class="comment">// with an appropriate StatusCode instead of an Err.</span>
<span class="prelude-val">Err</span>(<span class="string">&quot;not HTTP/1.1, abort connection&quot;</span>)
}
});</pre></div>
</div></section><section id="search" class="content hidden"></section><section class="footer"></section><div id="rustdoc-vars" data-root-path="../../" data-current-crate="hyper"></div>
<script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>
+39
View File
@@ -0,0 +1,39 @@
<!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="Asynchronous Services"><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">&#9776;</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><div id="sidebar-vars" data-name="service" data-ty="mod" data-relpath="../"></div><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="in-band">Module <a href="../index.html">hyper</a>::<wbr><a class="mod" href="">service</a></span><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/hyper/service/mod.rs.html#1-55" title="goto source code">[src]</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. Its similar to
<code>async fn(Request) -&gt; Result&lt;Response, Error&gt;</code>.</p>
<p>The argument and return value isnt 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&lt;http::Request&lt;B1&gt;, Response = http::Response&lt;B2&gt;&gt;</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><div id="rustdoc-vars" data-root-path="../../" data-current-crate="hyper"></div>
<script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../../hyper/service/fn.make_service_fn.html">
</head>
<body>
<p>Redirecting to <a href="../../../hyper/service/fn.make_service_fn.html">../../../hyper/service/fn.make_service_fn.html</a>...</p>
<script>location.replace("../../../hyper/service/fn.make_service_fn.html" + location.search + location.hash);</script>
</body>
</html>
+1
View File
@@ -0,0 +1 @@
initSidebarItems({"fn":[["make_service_fn","Create a `MakeService` from a function."],["service_fn","Create a `Service` from a function."]],"trait":[["Service","An asynchronous function from a `Request` to a `Response`."]]});
File diff suppressed because one or more lines are too long
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../../hyper/service/fn.service_fn.html">
</head>
<body>
<p>Redirecting to <a href="../../../hyper/service/fn.service_fn.html">../../../hyper/service/fn.service_fn.html</a>...</p>
<script>location.replace("../../../hyper/service/fn.service_fn.html" + location.search + location.hash);</script>
</body>
</html>