Files
GopherGate/target/doc/yoke/index.html
2026-02-26 12:00:21 -05:00

19 lines
7.5 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="This crate provides `Yoke&#60;Y, C&#62;`, which allows one to “yoke” (attach) a zero-copy deserialized object (say, a `Cow&#60;&#39;a, str&#62;`) to the source it was deserialized from, (say, an `Rc&#60;[u8]&#62;`), known in this crate as a “cart”, producing a type that looks like `Yoke&#60;Cow&#60;&#39;static, str&#62;, Rc&#60;[u8]&#62;&#62;` and can be moved around with impunity."><title>yoke - 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="yoke" 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="../crates.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 crate"><!--[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="#">Crate yoke</a></h2></rustdoc-topbar><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../yoke/index.html">yoke</a><span class="version">0.8.1</span></h2></div><div class="sidebar-elems"><ul class="block"><li><a id="all-types" href="all.html">All Items</a></li></ul><section id="rustdoc-toc"><h3><a href="#modules">Crate 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="#derives" title="Derive Macros">Derive Macros</a></li></ul></section><div id="rustdoc-modnav"></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"><h1>Crate <span>yoke</span>&nbsp;<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/yoke/lib.rs.html#5-68">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>This crate provides <a href="struct.Yoke.html" title="struct yoke::Yoke"><code>Yoke&lt;Y, C&gt;</code></a>, which allows one to “yoke” (attach) a zero-copy deserialized
object (say, a <a href="alloc::borrow::Cow"><code>Cow&lt;'a, str&gt;</code></a>) to the source it was deserialized from, (say, an <a href="alloc::rc::Rc"><code>Rc&lt;[u8]&gt;</code></a>),
known in this crate as a “cart”, producing a type that looks like <code>Yoke&lt;Cow&lt;'static, str&gt;, Rc&lt;[u8]&gt;&gt;</code>
and can be moved around with impunity.</p>
<p>Succinctly, this allows one to “erase” static lifetimes and turn them into dynamic ones, similarly
to how <code>dyn</code> allows one to “erase” static types and turn them into dynamic ones.</p>
<p>Most of the time the yokeable <code>Y</code> type will be some kind of zero-copy deserializable
abstraction, potentially with an owned variant (like <a href="alloc::borrow::Cow"><code>Cow</code></a>,
<a href="https://docs.rs/zerovec"><code>ZeroVec</code></a>, or an aggregate containing such types), and the cart <code>C</code> will be some smart pointer like
<a href="alloc::boxed::Box"><code>Box&lt;T&gt;</code></a>, <a href="alloc::rc::Rc"><code>Rc&lt;T&gt;</code></a>, or <a href="https://doc.rust-lang.org/1.93.1/alloc/sync/struct.Arc.html" title="struct alloc::sync::Arc"><code>Arc&lt;T&gt;</code></a>, potentially wrapped in an <a href="https://doc.rust-lang.org/1.93.1/core/option/enum.Option.html" title="enum core::option::Option"><code>Option&lt;T&gt;</code></a>.</p>
<p>The key behind this crate is <a href="struct.Yoke.html#method.get" title="method yoke::Yoke::get"><code>Yoke::get()</code></a>, where calling <a href="struct.Yoke.html#method.get" title="method yoke::Yoke::get"><code>.get()</code></a> on a type like
<code>Yoke&lt;Cow&lt;'static, str&gt;, _&gt;</code> will get you a short-lived <code>&amp;'a Cow&lt;'a, str&gt;</code>, restricted to the
lifetime of the borrow used during <a href="struct.Yoke.html#method.get" title="method yoke::Yoke::get"><code>.get()</code></a>. This is entirely safe since the <code>Cow</code> borrows from
the cart type <code>C</code>, which cannot be interfered with as long as the <code>Yoke</code> is borrowed by <a href="struct.Yoke.html#method.get" title="method yoke::Yoke::get"><code>.get()</code></a>.
<a href="struct.Yoke.html#method.get" title="method yoke::Yoke::get"><code>.get()</code></a> protects access by essentially reifying the erased lifetime to a safe local one
when necessary.</p>
<p>See the documentation of <a href="struct.Yoke.html" title="struct yoke::Yoke"><code>Yoke</code></a> for more details.</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="cartable_ptr/index.html" title="mod yoke::cartable_ptr">cartable_<wbr>ptr</a></dt><dd>Types for optional pointers with niche optimization.</dd><dt><a class="mod" href="either/index.html" title="mod yoke::either">either</a></dt><dd>Types to enable polymorphic carts.</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.Yoke.html" title="struct yoke::Yoke">Yoke</a></dt><dd>A Cow-like borrowed object “yoked” to its backing data.</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.CloneableCart.html" title="trait yoke::CloneableCart">Cloneable<wbr>Cart</a></dt><dd>This trait marks cart types that do not change source on cloning</dd><dt><a class="trait" href="trait.Yokeable.html" title="trait yoke::Yokeable">Yokeable</a></dt><dd>The <code>Yokeable&lt;'a&gt;</code> trait is implemented on the <code>'static</code> version of any zero-copy type; for
example, <code>Cow&lt;'static, T&gt;</code> implements <code>Yokeable&lt;'a&gt;</code> (for all <code>'a</code>).</dd></dl><h2 id="derives" class="section-header">Derive Macros<a href="#derives" class="anchor">§</a></h2><dl class="item-table"><dt><a class="derive" href="derive.Yokeable.html" title="derive yoke::Yokeable">Yokeable</a></dt><dd>Custom derive for <code>yoke::Yokeable</code>,</dd></dl></section></div></main></body></html>