48 lines
9.8 KiB
HTML
48 lines
9.8 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="Connectors used by the `Client`."><title>hyper_util::client::legacy::connect - 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="hyper_util" 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 mod"><!--[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="#">Module connect</a></h2></rustdoc-topbar><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../../../hyper_util/index.html">hyper_<wbr>util</a><span class="version">0.1.20</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Module connect</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#connectors" title="Connectors">Connectors</a><ul><li><a href="#custom-connectors" title="Custom Connectors">Custom Connectors</a></li></ul></li></ul><h3><a href="#modules">Module Items</a></h3><ul class="block"><li><a href="#modules" title="Modules">Modules</a></li><li><a href="#structs" title="Structs">Structs</a></li><li><a href="#traits" title="Traits">Traits</a></li><li><a href="#functions" title="Functions">Functions</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="../index.html">In hyper_<wbr>util::<wbr>client::<wbr>legacy</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">hyper_util</a>::<wbr><a href="../../index.html">client</a>::<wbr><a href="../index.html">legacy</a></div><h1>Module <span>connect</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/hyper_util/client/legacy/connect/mod.rs.html#1-444">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Connectors used by the <code>Client</code>.</p>
|
||
<p>This module contains:</p>
|
||
<ul>
|
||
<li>A default <a href="struct.HttpConnector.html" title="struct hyper_util::client::legacy::connect::HttpConnector"><code>HttpConnector</code></a> that does DNS resolution and establishes
|
||
connections over TCP.</li>
|
||
<li>Types to build custom connectors.</li>
|
||
</ul>
|
||
<h2 id="connectors"><a class="doc-anchor" href="#connectors">§</a>Connectors</h2>
|
||
<p>A “connector” is a <a href="../../../../tower_service/trait.Service.html" title="trait tower_service::Service"><code>Service</code></a> that takes a <a href="../../../../http/uri/struct.Uri.html" title="struct http::uri::Uri"><code>Uri</code></a> destination, and
|
||
its <code>Response</code> is some type implementing <a href="../../../../hyper/rt/io/trait.Read.html" title="trait hyper::rt::io::Read"><code>Read</code></a>, <a href="../../../../hyper/rt/io/trait.Write.html" title="trait hyper::rt::io::Write"><code>Write</code></a>,
|
||
and <a href="trait.Connection.html" title="trait hyper_util::client::legacy::connect::Connection"><code>Connection</code></a>.</p>
|
||
<h3 id="custom-connectors"><a class="doc-anchor" href="#custom-connectors">§</a>Custom Connectors</h3>
|
||
<p>A simple connector that ignores the <code>Uri</code> destination and always returns
|
||
a TCP connection to the same address could be written like this:</p>
|
||
|
||
<div class="example-wrap ignore"><a href="#" class="tooltip" title="This example is not tested">ⓘ</a><pre class="rust rust-example-rendered"><code><span class="kw">let </span>connector = tower::service_fn(|_dst| <span class="kw">async </span>{
|
||
tokio::net::TcpStream::connect(<span class="string">"127.0.0.1:1337"</span>)
|
||
})</code></pre></div>
|
||
<p>Or, fully written out:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::{future::Future, net::SocketAddr, pin::Pin, task::{<span class="self">self</span>, Poll}};
|
||
<span class="kw">use </span>http::Uri;
|
||
<span class="kw">use </span>tokio::net::TcpStream;
|
||
<span class="kw">use </span>tower_service::Service;
|
||
|
||
<span class="attr">#[derive(Clone)]
|
||
</span><span class="kw">struct </span>LocalConnector;
|
||
|
||
<span class="kw">impl </span>Service<Uri> <span class="kw">for </span>LocalConnector {
|
||
<span class="kw">type </span>Response = TcpStream;
|
||
<span class="kw">type </span>Error = std::io::Error;
|
||
<span class="comment">// We can't "name" an `async` generated future.
|
||
</span><span class="kw">type </span>Future = Pin<Box<
|
||
<span class="kw">dyn </span>Future<Output = <span class="prelude-ty">Result</span><<span class="self">Self</span>::Response, <span class="self">Self</span>::Error>> + Send
|
||
>>;
|
||
|
||
<span class="kw">fn </span>poll_ready(<span class="kw-2">&mut </span><span class="self">self</span>, <span class="kw">_</span>: <span class="kw-2">&mut </span>task::Context<<span class="lifetime">'_</span>>) -> Poll<<span class="prelude-ty">Result</span><(), <span class="self">Self</span>::Error>> {
|
||
<span class="comment">// This connector is always ready, but others might not be.
|
||
</span>Poll::Ready(<span class="prelude-val">Ok</span>(()))
|
||
}
|
||
|
||
<span class="kw">fn </span>call(<span class="kw-2">&mut </span><span class="self">self</span>, <span class="kw">_</span>: Uri) -> <span class="self">Self</span>::Future {
|
||
Box::pin(TcpStream::connect(SocketAddr::from(([<span class="number">127</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">1</span>], <span class="number">1337</span>))))
|
||
}
|
||
}</code></pre></div>
|
||
<p>It’s worth noting that for <code>TcpStream</code>s, the <a href="struct.HttpConnector.html" title="struct hyper_util::client::legacy::connect::HttpConnector"><code>HttpConnector</code></a> is a
|
||
better starting place to extend from.</p>
|
||
</div></details><h2 id="modules" class="section-header">Modules<a href="#modules" class="anchor">§</a></h2><dl class="item-table"><dt><a class="mod" href="dns/index.html" title="mod hyper_util::client::legacy::connect::dns">dns</a></dt><dd>DNS Resolution used by the <code>HttpConnector</code>.</dd><dt><a class="mod" href="proxy/index.html" title="mod hyper_util::client::legacy::connect::proxy">proxy</a></dt><dd>Proxy helpers</dd></dl><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><dl class="item-table"><dt><a class="struct" href="struct.CaptureConnection.html" title="struct hyper_util::client::legacy::connect::CaptureConnection">Capture<wbr>Connection</a></dt><dd><a href="struct.CaptureConnection.html" title="struct hyper_util::client::legacy::connect::CaptureConnection"><code>CaptureConnection</code></a> allows callers to capture <a href="struct.Connected.html" title="struct hyper_util::client::legacy::connect::Connected"><code>Connected</code></a> information</dd><dt><a class="struct" href="struct.Connected.html" title="struct hyper_util::client::legacy::connect::Connected">Connected</a></dt><dd>Extra information about the connected transport.</dd><dt><a class="struct" href="struct.HttpConnector.html" title="struct hyper_util::client::legacy::connect::HttpConnector">Http<wbr>Connector</a></dt><dd>A connector for the <code>http</code> scheme.</dd><dt><a class="struct" href="struct.HttpInfo.html" title="struct hyper_util::client::legacy::connect::HttpInfo">Http<wbr>Info</a></dt><dd>Extra information about the transport when an HttpConnector is used.</dd></dl><h2 id="traits" class="section-header">Traits<a href="#traits" class="anchor">§</a></h2><dl class="item-table"><dt><a class="trait" href="trait.Connect.html" title="trait hyper_util::client::legacy::connect::Connect">Connect</a></dt><dd>Connect to a destination, returning an IO transport.</dd><dt><a class="trait" href="trait.Connection.html" title="trait hyper_util::client::legacy::connect::Connection">Connection</a></dt><dd>Describes a type returned by a connector.</dd></dl><h2 id="functions" class="section-header">Functions<a href="#functions" class="anchor">§</a></h2><dl class="item-table"><dt><a class="fn" href="fn.capture_connection.html" title="fn hyper_util::client::legacy::connect::capture_connection">capture_<wbr>connection</a></dt><dd>Capture the connection for a given request</dd></dl></section></div></main></body></html> |