Files
phy/zeno/trait.PathData.html
Orion Kindel 0ce894e6b0 doc
2025-03-18 10:30:23 -05:00

65 lines
20 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="Trait for types that represent path data."><title>PathData in zeno - 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="zeno" 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="../zeno/index.html">zeno</a><span class="version">0.2.3</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Path<wbr>Data</a></h2><h3><a href="#required-associated-types">Required Associated Types</a></h3><ul class="block"><li><a href="#associatedtype.Commands" title="Commands">Commands</a></li></ul><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.commands" title="commands">commands</a></li></ul><h3><a href="#provided-methods">Provided Methods</a></h3><ul class="block"><li><a href="#method.copy_to" title="copy_to">copy_to</a></li></ul><h3><a href="#foreign-impls">Implementations on Foreign Types</a></h3><ul class="block"><li><a href="#impl-PathData-for-%26Vec%3CCommand%3E" title="&#38;&#39;a Vec&#60;Command&#62;">&#38;&#39;a Vec&#60;Command&#62;</a></li><li><a href="#impl-PathData-for-%26%5BCommand%5D" title="&#38;&#39;a [Command]">&#38;&#39;a [Command]</a></li><li><a href="#impl-PathData-for-%26str" title="&#38;&#39;a str">&#38;&#39;a str</a></li><li><a href="#impl-PathData-for-%26T" title="&#38;T">&#38;T</a></li><li><a href="#impl-PathData-for-(%26%5BVector%5D,+%26%5BVerb%5D)" title="(&#38;&#39;a [Point], &#38;&#39;a [Verb])">(&#38;&#39;a [Point], &#38;&#39;a [Verb])</a></li></ul><h3><a href="#dyn-compatibility">Dyn Compatibility</a></h3><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="index.html">In crate zeno</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">zeno</a></span><h1>Trait <span class="trait">PathData</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/zeno/path_data.rs.html#85-105">Source</a> </span></div><pre class="rust item-decl"><code>pub trait PathData {
type <a href="#associatedtype.Commands" class="associatedtype">Commands</a>: <a class="trait" href="https://doc.rust-lang.org/1.84.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a>&lt;Item = <a class="enum" href="enum.Command.html" title="enum zeno::Command">Command</a>&gt; + <a class="trait" href="https://doc.rust-lang.org/1.84.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>;
// Required method
fn <a href="#tymethod.commands" class="fn">commands</a>(&amp;self) -&gt; Self::<a class="associatedtype" href="trait.PathData.html#associatedtype.Commands" title="type zeno::PathData::Commands">Commands</a>;
// Provided method
fn <a href="#method.copy_to" class="fn">copy_to</a>(&amp;self, sink: &amp;mut impl <a class="trait" href="trait.PathBuilder.html" title="trait zeno::PathBuilder">PathBuilder</a>) { ... }
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Trait for types that represent path data.</p>
<p>A primary design goal for this crate is to be agnostic with regard to
storage of path data. This trait provides the abstraction to make that
possible.</p>
<p>All path data is consumed internally as an iterator over path
<a href="enum.Command.html">commands</a> and as such, this trait is similar to
the IntoIterator trait, but restricted to iterators of commands and
without consuming itself.</p>
<p>Implementations of this trait are provided for SVG path data (in the form
of strings), slices/vectors of commands, and the common point and
verb list structure (as the tuple <code>(&amp;[Point], &amp;[Verb])</code>).</p>
<p>As such, these paths are all equivalent:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>zeno::{Command, PathData, Point, Verb};
<span class="comment">// SVG path data
</span><span class="kw">let </span>path1 = <span class="string">"M1,2 L3,4"</span>;
<span class="comment">// Slice of commands
</span><span class="kw">let </span>path2 = <span class="kw-2">&amp;</span>[
Command::MoveTo(Point::new(<span class="number">1.0</span>, <span class="number">2.0</span>)),
Command::LineTo(Point::new(<span class="number">3.0</span>, <span class="number">4.0</span>)),
][..];
<span class="comment">// Tuple of slices to points and verbs
</span><span class="kw">let </span>path3 = (
<span class="kw-2">&amp;</span>[Point::new(<span class="number">1.0</span>, <span class="number">2.0</span>), Point::new(<span class="number">3.0</span>, <span class="number">4.0</span>)][..],
<span class="kw-2">&amp;</span>[Verb::MoveTo, Verb::LineTo][..],
);
<span class="macro">assert!</span>(path1.commands().eq(path2.commands()));
<span class="macro">assert!</span>(path2.commands().eq(path3.commands()));</code></pre></div>
<p>Implementing PathData is similar to implementing IntoIterator:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>zeno::{Command, PathData};
<span class="kw">pub struct </span>MyPath {
data: Vec&lt;Command&gt;
}
<span class="kw">impl</span>&lt;<span class="lifetime">'a</span>&gt; PathData <span class="kw">for </span><span class="kw-2">&amp;</span><span class="lifetime">'a </span>MyPath {
<span class="comment">// Copied here because PathData expects Commands by value
</span><span class="kw">type </span>Commands = std::iter::Copied&lt;std::slice::Iter&lt;<span class="lifetime">'a</span>, Command&gt;&gt;;
<span class="kw">fn </span>commands(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; <span class="self">Self</span>::Commands {
<span class="self">self</span>.data.iter().copied()
}
}</code></pre></div>
<p>The provided copy_into() method evaluates the command iterator and
submits the commands to a sink. You should also implement this if you
have a more direct method of dispatching to a sink as rasterizer
performance can be sensitive to latencies here.</p>
</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.Commands" class="method"><a class="src rightside" href="../src/zeno/path_data.rs.html#87">Source</a><h4 class="code-header">type <a href="#associatedtype.Commands" class="associatedtype">Commands</a>: <a class="trait" href="https://doc.rust-lang.org/1.84.0/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a>&lt;Item = <a class="enum" href="enum.Command.html" title="enum zeno::Command">Command</a>&gt; + <a class="trait" href="https://doc.rust-lang.org/1.84.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a></h4></section></summary><div class="docblock"><p>Command iterator.</p>
</div></details></div><h2 id="required-methods" class="section-header">Required Methods<a href="#required-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="tymethod.commands" class="method"><a class="src rightside" href="../src/zeno/path_data.rs.html#90">Source</a><h4 class="code-header">fn <a href="#tymethod.commands" class="fn">commands</a>(&amp;self) -&gt; Self::<a class="associatedtype" href="trait.PathData.html#associatedtype.Commands" title="type zeno::PathData::Commands">Commands</a></h4></section></summary><div class="docblock"><p>Returns an iterator over the commands described by the path data.</p>
</div></details></div><h2 id="provided-methods" class="section-header">Provided Methods<a href="#provided-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="method.copy_to" class="method"><a class="src rightside" href="../src/zeno/path_data.rs.html#93-104">Source</a><h4 class="code-header">fn <a href="#method.copy_to" class="fn">copy_to</a>(&amp;self, sink: &amp;mut impl <a class="trait" href="trait.PathBuilder.html" title="trait zeno::PathBuilder">PathBuilder</a>)</h4></section></summary><div class="docblock"><p>Copies the path data into the specified sink.</p>
</div></details></div><h2 id="dyn-compatibility" class="section-header">Dyn Compatibility<a href="#dyn-compatibility" class="anchor">§</a></h2><div class="dyn-compatibility-info"><p>This trait is <b>not</b> <a href="https://doc.rust-lang.org/1.84.0/reference/items/traits.html#object-safety">dyn compatible</a>.</p><p><i>In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.</i></p></div><h2 id="foreign-impls" class="section-header">Implementations on Foreign Types<a href="#foreign-impls" class="anchor">§</a></h2><details class="toggle implementors-toggle"><summary><section id="impl-PathData-for-%26str" class="impl"><a class="src rightside" href="../src/zeno/path_data.rs.html#193-199">Source</a><a href="#impl-PathData-for-%26str" class="anchor">§</a><h3 class="code-header">impl&lt;'a&gt; <a class="trait" href="trait.PathData.html" title="trait zeno::PathData">PathData</a> for &amp;'a <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.str.html">str</a></h3></section></summary><div class="impl-items"><section id="associatedtype.Commands-1" class="associatedtype trait-impl"><a class="src rightside" href="../src/zeno/path_data.rs.html#194">Source</a><a href="#associatedtype.Commands-1" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.Commands" class="associatedtype">Commands</a> = SvgCommands&lt;'a&gt;</h4></section><section id="method.commands" class="method trait-impl"><a class="src rightside" href="../src/zeno/path_data.rs.html#196-198">Source</a><a href="#method.commands" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.commands" class="fn">commands</a>(&amp;self) -&gt; Self::<a class="associatedtype" href="trait.PathData.html#associatedtype.Commands" title="type zeno::PathData::Commands">Commands</a></h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-PathData-for-%26Vec%3CCommand%3E" class="impl"><a class="src rightside" href="../src/zeno/path_data.rs.html#222-228">Source</a><a href="#impl-PathData-for-%26Vec%3CCommand%3E" class="anchor">§</a><h3 class="code-header">impl&lt;'a&gt; <a class="trait" href="trait.PathData.html" title="trait zeno::PathData">PathData</a> for &amp;'a <a class="struct" href="https://doc.rust-lang.org/1.84.0/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a>&lt;<a class="enum" href="enum.Command.html" title="enum zeno::Command">Command</a>&gt;</h3></section></summary><div class="impl-items"><section id="associatedtype.Commands-2" class="associatedtype trait-impl"><a class="src rightside" href="../src/zeno/path_data.rs.html#223">Source</a><a href="#associatedtype.Commands-2" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.Commands" class="associatedtype">Commands</a> = <a class="struct" href="https://doc.rust-lang.org/1.84.0/core/iter/adapters/copied/struct.Copied.html" title="struct core::iter::adapters::copied::Copied">Copied</a>&lt;<a class="struct" href="https://doc.rust-lang.org/1.84.0/core/slice/iter/struct.Iter.html" title="struct core::slice::iter::Iter">Iter</a>&lt;'a, <a class="enum" href="enum.Command.html" title="enum zeno::Command">Command</a>&gt;&gt;</h4></section><section id="method.commands-1" class="method trait-impl"><a class="src rightside" href="../src/zeno/path_data.rs.html#225-227">Source</a><a href="#method.commands-1" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.commands" class="fn">commands</a>(&amp;self) -&gt; Self::<a class="associatedtype" href="trait.PathData.html#associatedtype.Commands" title="type zeno::PathData::Commands">Commands</a></h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-PathData-for-%26%5BCommand%5D" class="impl"><a class="src rightside" href="../src/zeno/path_data.rs.html#214-220">Source</a><a href="#impl-PathData-for-%26%5BCommand%5D" class="anchor">§</a><h3 class="code-header">impl&lt;'a&gt; <a class="trait" href="trait.PathData.html" title="trait zeno::PathData">PathData</a> for &amp;'a [<a class="enum" href="enum.Command.html" title="enum zeno::Command">Command</a>]</h3></section></summary><div class="impl-items"><section id="associatedtype.Commands-3" class="associatedtype trait-impl"><a class="src rightside" href="../src/zeno/path_data.rs.html#215">Source</a><a href="#associatedtype.Commands-3" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.Commands" class="associatedtype">Commands</a> = <a class="struct" href="https://doc.rust-lang.org/1.84.0/core/iter/adapters/copied/struct.Copied.html" title="struct core::iter::adapters::copied::Copied">Copied</a>&lt;<a class="struct" href="https://doc.rust-lang.org/1.84.0/core/slice/iter/struct.Iter.html" title="struct core::slice::iter::Iter">Iter</a>&lt;'a, <a class="enum" href="enum.Command.html" title="enum zeno::Command">Command</a>&gt;&gt;</h4></section><section id="method.commands-2" class="method trait-impl"><a class="src rightside" href="../src/zeno/path_data.rs.html#217-219">Source</a><a href="#method.commands-2" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.commands" class="fn">commands</a>(&amp;self) -&gt; Self::<a class="associatedtype" href="trait.PathData.html#associatedtype.Commands" title="type zeno::PathData::Commands">Commands</a></h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-PathData-for-(%26%5BVector%5D,+%26%5BVerb%5D)" class="impl"><a class="src rightside" href="../src/zeno/path_data.rs.html#201-212">Source</a><a href="#impl-PathData-for-(%26%5BVector%5D,+%26%5BVerb%5D)" class="anchor">§</a><h3 class="code-header">impl&lt;'a&gt; <a class="trait" href="trait.PathData.html" title="trait zeno::PathData">PathData</a> for (&amp;'a [<a class="type" href="type.Point.html" title="type zeno::Point">Point</a>], &amp;'a [<a class="enum" href="enum.Verb.html" title="enum zeno::Verb">Verb</a>])</h3></section></summary><div class="impl-items"><section id="associatedtype.Commands-4" class="associatedtype trait-impl"><a class="src rightside" href="../src/zeno/path_data.rs.html#202">Source</a><a href="#associatedtype.Commands-4" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.Commands" class="associatedtype">Commands</a> = PointsCommands&lt;'a&gt;</h4></section><section id="method.commands-3" class="method trait-impl"><a class="src rightside" href="../src/zeno/path_data.rs.html#204-206">Source</a><a href="#method.commands-3" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.commands" class="fn">commands</a>(&amp;self) -&gt; Self::<a class="associatedtype" href="trait.PathData.html#associatedtype.Commands" title="type zeno::PathData::Commands">Commands</a></h4></section><section id="method.copy_to-1" class="method trait-impl"><a class="src rightside" href="../src/zeno/path_data.rs.html#209-211">Source</a><a href="#method.copy_to-1" class="anchor">§</a><h4 class="code-header">fn <a href="#method.copy_to" class="fn">copy_to</a>(&amp;self, sink: &amp;mut impl <a class="trait" href="trait.PathBuilder.html" title="trait zeno::PathBuilder">PathBuilder</a>)</h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-PathData-for-%26T" class="impl"><a class="src rightside" href="../src/zeno/path_data.rs.html#177-191">Source</a><a href="#impl-PathData-for-%26T" class="anchor">§</a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="trait.PathData.html" title="trait zeno::PathData">PathData</a> for <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.reference.html">&amp;T</a><div class="where">where
T: <a class="trait" href="trait.PathData.html" title="trait zeno::PathData">PathData</a>,</div></h3></section></summary><div class="impl-items"><section id="associatedtype.Commands-5" class="associatedtype trait-impl"><a class="src rightside" href="../src/zeno/path_data.rs.html#181">Source</a><a href="#associatedtype.Commands-5" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.Commands" class="associatedtype">Commands</a> = &lt;T as <a class="trait" href="trait.PathData.html" title="trait zeno::PathData">PathData</a>&gt;::<a class="associatedtype" href="trait.PathData.html#associatedtype.Commands" title="type zeno::PathData::Commands">Commands</a></h4></section><section id="method.commands-4" class="method trait-impl"><a class="src rightside" href="../src/zeno/path_data.rs.html#183-185">Source</a><a href="#method.commands-4" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.commands" class="fn">commands</a>(&amp;self) -&gt; Self::<a class="associatedtype" href="trait.PathData.html#associatedtype.Commands" title="type zeno::PathData::Commands">Commands</a></h4></section><section id="method.copy_to-2" class="method trait-impl"><a class="src rightside" href="../src/zeno/path_data.rs.html#188-190">Source</a><a href="#method.copy_to-2" class="anchor">§</a><h4 class="code-header">fn <a href="#method.copy_to" class="fn">copy_to</a>(&amp;self, sink: &amp;mut impl <a class="trait" href="trait.PathBuilder.html" title="trait zeno::PathBuilder">PathBuilder</a>)</h4></section></div></details><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"></div><script src="../trait.impl/zeno/path_data/trait.PathData.js" data-ignore-extern-crates="std,alloc" async></script></section></div></main></body></html>