34 lines
13 KiB
HTML
34 lines
13 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="An `Equiv` type is one that is conceptually the same as some different type."><title>Equiv in naan - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.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" crossorigin href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="naan" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.0 (9fc6b4312 2025-01-07)" data-channel="1.84.0" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-6580c154.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]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../naan/index.html">naan</a><span class="version">0.1.32</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Equiv</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#example---iterators" title="Example - Iterators">Example - Iterators</a></li></ul><h3><a href="#required-associated-types">Required Associated Types</a></h3><ul class="block"><li><a href="#associatedtype.To" title="To">To</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 naan</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="index.html">naan</a></span><h1>Trait <span class="trait">Equiv</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/naan/lib.rs.html#760-763">Source</a> </span></div><pre class="rust item-decl"><code>pub trait Equiv {
|
|
type <a href="#associatedtype.To" class="associatedtype">To</a>;
|
|
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>An <code>Equiv</code> type is one that is conceptually the same as some
|
|
different type.</p>
|
|
<p>This is used to allow types to implement typeclasses for other types
|
|
in a still strict way. For examples see <a href="functor/trait.FunctorSurrogate.html" title="trait naan::functor::FunctorSurrogate"><code>functor::FunctorSurrogate</code></a>, <a href="monad/trait.MonadSurrogate.html" title="trait naan::monad::MonadSurrogate"><code>monad::MonadSurrogate</code></a></p>
|
|
<h2 id="example---iterators"><a class="doc-anchor" href="#example---iterators">§</a>Example - Iterators</h2>
|
|
<p>In the following example, <code>iter</code> <code>map</code> and <code>filter</code> are all
|
|
conceptually “an iterator over <code>usize</code>”</p>
|
|
|
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::iter::{Filter, Map};
|
|
|
|
<span class="kw">let </span>vec: Vec<usize> = <span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>];
|
|
<span class="kw">let </span>iter: std::vec::IntoIter<usize> = vec.into_iter();
|
|
<span class="kw">let </span>map: Map<std::vec::IntoIter<usize>, <span class="kw">_</span>> = iter.map(|n| n + <span class="number">1</span>);
|
|
<span class="kw">let </span>filter: Filter<Map<std::vec::IntoIter<usize>, <span class="kw">_</span>>, <span class="kw">_</span>> = map.filter(|n| n % <span class="number">2 </span>== <span class="number">0</span>);</code></pre></div>
|
|
<p>this would imply:</p>
|
|
|
|
<div class="example-wrap ignore"><a href="#" class="tooltip" title="This example is not tested">ⓘ</a><pre class="rust rust-example-rendered"><code><std::vec::IntoIter<usize> <span class="kw">as </span>Equiv>::To == std::vec::IntoIter<usize>
|
|
<Map<std::vec::IntoIter<usize>, <span class="kw">_</span>> <span class="kw">as </span>Equiv>::To == std::vec::IntoIter<usize>
|
|
<Filter<Map<std::vec::IntoIter<usize>, <span class="kw">_</span>>, <span class="kw">_</span>> <span class="kw">as </span>Equiv>::To == std::vec::IntoIter<usize></code></pre></div>
|
|
<p>Other examples:</p>
|
|
<ul>
|
|
<li><code>Result<A, Infallible></code> is <code>Equiv::To</code> <code>Result<A, !></code> (and vice versa)</li>
|
|
<li><code>IO<Lazy></code> is <code>Equiv::To</code> <code>IO<Lazy::T></code> (<code>IO<Suspend<_, usize>></code> == <code>IO<usize></code>)</li>
|
|
</ul>
|
|
</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.To" class="method"><a class="src rightside" href="../src/naan/lib.rs.html#762">Source</a><h4 class="code-header">type <a href="#associatedtype.To" class="associatedtype">To</a></h4></section></summary><div class="docblock"><p>The target that <code>Self</code> is conceptually equivalent to</p>
|
|
</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-Equiv-for-IO%3CA%3E" class="impl"><a class="src rightside" href="../src/naan/io/mod.rs.html#184-186">Source</a><a href="#impl-Equiv-for-IO%3CA%3E" class="anchor">§</a><h3 class="code-header">impl<A> <a class="trait" href="trait.Equiv.html" title="trait naan::Equiv">Equiv</a> for <a class="struct" href="io/struct.IO.html" title="struct naan::io::IO">IO</a><A></h3></section></summary><div class="impl-items"><section id="associatedtype.To-1" class="associatedtype trait-impl"><a class="src rightside" href="../src/naan/io/mod.rs.html#185">Source</a><a href="#associatedtype.To-1" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.To" class="associatedtype">To</a> = <a class="struct" href="io/struct.IO.html" title="struct naan::io::IO">IO</a><A></h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Equiv-for-Apply%3CA,+B,+AB,+IOA,+IOAB%3E" class="impl"><a class="src rightside" href="../src/naan/io/apply.rs.html#19-21">Source</a><a href="#impl-Equiv-for-Apply%3CA,+B,+AB,+IOA,+IOAB%3E" class="anchor">§</a><h3 class="code-header">impl<A, B, AB, IOA, IOAB> <a class="trait" href="trait.Equiv.html" title="trait naan::Equiv">Equiv</a> for <a class="struct" href="io/apply/struct.Apply.html" title="struct naan::io::apply::Apply">Apply</a><A, B, AB, IOA, IOAB></h3></section></summary><div class="impl-items"><section id="associatedtype.To-2" class="associatedtype trait-impl"><a class="src rightside" href="../src/naan/io/apply.rs.html#20">Source</a><a href="#associatedtype.To-2" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.To" class="associatedtype">To</a> = <a class="struct" href="io/struct.IO.html" title="struct naan::io::IO">IO</a><B></h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Equiv-for-Suspend%3CF%3E" class="impl"><a class="src rightside" href="../src/naan/io/suspend.rs.html#8-12">Source</a><a href="#impl-Equiv-for-Suspend%3CF%3E" class="anchor">§</a><h3 class="code-header">impl<F> <a class="trait" href="trait.Equiv.html" title="trait naan::Equiv">Equiv</a> for <a class="struct" href="io/suspend/struct.Suspend.html" title="struct naan::io::suspend::Suspend">Suspend</a><F><div class="where">where
|
|
F: <a class="trait" href="fun/trait.F1Once.html" title="trait naan::fun::F1Once">F1Once</a><<a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.unit.html">()</a>>,</div></h3></section></summary><div class="impl-items"><section id="associatedtype.To-3" class="associatedtype trait-impl"><a class="src rightside" href="../src/naan/io/suspend.rs.html#11">Source</a><a href="#associatedtype.To-3" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.To" class="associatedtype">To</a> = <a class="struct" href="io/struct.IO.html" title="struct naan::io::IO">IO</a><<F as <a class="trait" href="fun/trait.F1Once.html" title="trait naan::fun::F1Once">F1Once</a><<a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.unit.html">()</a>>>::<a class="associatedtype" href="fun/trait.F1Once.html#associatedtype.Ret" title="type naan::fun::F1Once::Ret">Ret</a>></h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Equiv-for-Bind%3CF,+A,+B,+IOA%3E" class="impl"><a class="src rightside" href="../src/naan/io/bind.rs.html#48-55">Source</a><a href="#impl-Equiv-for-Bind%3CF,+A,+B,+IOA%3E" class="anchor">§</a><h3 class="code-header">impl<F, A, B, IOA> <a class="trait" href="trait.Equiv.html" title="trait naan::Equiv">Equiv</a> for <a class="struct" href="io/bind/struct.Bind.html" title="struct naan::io::bind::Bind">Bind</a><F, A, B, IOA><div class="where">where
|
|
F: <a class="trait" href="fun/trait.F1Once.html" title="trait naan::fun::F1Once">F1Once</a><A>,
|
|
F::<a class="associatedtype" href="fun/trait.F1Once.html#associatedtype.Ret" title="type naan::fun::F1Once::Ret">Ret</a>: <a class="trait" href="trait.Equiv.html" title="trait naan::Equiv">Equiv</a><To = <a class="struct" href="io/struct.IO.html" title="struct naan::io::IO">IO</a><B>>,
|
|
IOA: <a class="trait" href="trait.Equiv.html" title="trait naan::Equiv">Equiv</a><To = <a class="struct" href="io/struct.IO.html" title="struct naan::io::IO">IO</a><A>>,</div></h3></section></summary><div class="impl-items"><section id="associatedtype.To-4" class="associatedtype trait-impl"><a class="src rightside" href="../src/naan/io/bind.rs.html#54">Source</a><a href="#associatedtype.To-4" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.To" class="associatedtype">To</a> = <a class="struct" href="io/struct.IO.html" title="struct naan::io::IO">IO</a><B></h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Equiv-for-Map%3CF,+X,+A,+IOX%3E" class="impl"><a class="src rightside" href="../src/naan/io/map.rs.html#48-54">Source</a><a href="#impl-Equiv-for-Map%3CF,+X,+A,+IOX%3E" class="anchor">§</a><h3 class="code-header">impl<F, X, A, IOX> <a class="trait" href="trait.Equiv.html" title="trait naan::Equiv">Equiv</a> for <a class="struct" href="io/map/struct.Map.html" title="struct naan::io::map::Map">Map</a><F, X, A, IOX><div class="where">where
|
|
F: <a class="trait" href="fun/trait.F1Once.html" title="trait naan::fun::F1Once">F1Once</a><X>,
|
|
IOX: <a class="trait" href="trait.Equiv.html" title="trait naan::Equiv">Equiv</a><To = <a class="struct" href="io/struct.IO.html" title="struct naan::io::IO">IO</a><X>>,</div></h3></section></summary><div class="impl-items"><section id="associatedtype.To-5" class="associatedtype trait-impl"><a class="src rightside" href="../src/naan/io/map.rs.html#53">Source</a><a href="#associatedtype.To-5" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.To" class="associatedtype">To</a> = <a class="struct" href="io/struct.IO.html" title="struct naan::io::IO">IO</a><<F as <a class="trait" href="fun/trait.F1Once.html" title="trait naan::fun::F1Once">F1Once</a><X>>::<a class="associatedtype" href="fun/trait.F1Once.html#associatedtype.Ret" title="type naan::fun::F1Once::Ret">Ret</a>></h4></section></div></details></div><script src="../trait.impl/naan/trait.Equiv.js" async></script></section></div></main></body></html> |