<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>Bristle</title>
  <link href="https://juicer.build/themes/juicerapi/demo/feed.xml" rel="self"/>
  <link href="https://juicer.build/themes/juicerapi/demo/"/>
  <id>https://juicer.build/themes/juicerapi/demo/feed.xml</id>
  <updated>2026-08-25T22:28:57.485307746Z</updated>
  <author><name>Unnamed</name></author>
  <entry>
    <title>bristle.text</title>
    <link href="https://juicer.build/themes/juicerapi/demo/text/"/>
    <id>https://juicer.build/themes/juicerapi/demo/text/</id>
    <updated>2026-08-25T22:28:57.485307746Z</updated>
    <summary>Searching, splitting and trimming over UTF-8 strings. Every function here answers a slice of its argument rather than a copy, so the module needs no allocator.</summary>
    <content type="html">&lt;h2 id=&quot;index&quot;&gt;Index&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;#starts_with&quot;&gt;&lt;code&gt;starts_with&lt;/code&gt;&lt;/a&gt; &lt;a href=&quot;#ends_with&quot;&gt;&lt;code&gt;ends_with&lt;/code&gt;&lt;/a&gt; &lt;a href=&quot;#find&quot;&gt;&lt;code&gt;find&lt;/code&gt;&lt;/a&gt;
&lt;a href=&quot;#split_once&quot;&gt;&lt;code&gt;split_once&lt;/code&gt;&lt;/a&gt; &lt;a href=&quot;#trim&quot;&gt;&lt;code&gt;trim&lt;/code&gt;&lt;/a&gt; &lt;a href=&quot;#cursor&quot;&gt;&lt;code&gt;Cursor&lt;/code&gt;&lt;/a&gt;
&lt;a href=&quot;#utf8error&quot;&gt;&lt;code&gt;Utf8Error&lt;/code&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;functions&quot;&gt;Functions&lt;/h2&gt;
&lt;h3 id=&quot;starts_with&quot;&gt;&lt;code&gt;starts_with&lt;/code&gt;&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-sysl&quot;&gt;&lt;span class=&quot;hl-function&quot;&gt;starts_with&lt;/span&gt;(s: []&lt;span class=&quot;hl-keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;hl-type&quot;&gt;u8&lt;/span&gt;, prefix: []&lt;span class=&quot;hl-keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;hl-type&quot;&gt;u8&lt;/span&gt;) -&amp;gt; &lt;span class=&quot;hl-type&quot;&gt;bool&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Answers whether &lt;code&gt;s&lt;/code&gt; begins with &lt;code&gt;prefix&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;An empty prefix is present in every string, so &lt;code&gt;starts_with(s, &amp;quot;&amp;quot;)&lt;/code&gt; answers
&lt;code&gt;true&lt;/code&gt; for every &lt;code&gt;s&lt;/code&gt; — including an empty one.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Parameter&lt;/th&gt;&lt;th&gt;Type&lt;/th&gt;&lt;th&gt;Description&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;s&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;[]const u8&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the bytes to test&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;prefix&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;[]const u8&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the prefix to look for&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;Returns&lt;/strong&gt; &lt;code&gt;bool&lt;/code&gt; — &lt;code&gt;true&lt;/code&gt; when &lt;code&gt;s&lt;/code&gt; begins with &lt;code&gt;prefix&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&quot;ends_with&quot;&gt;&lt;code&gt;ends_with&lt;/code&gt;&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-sysl&quot;&gt;&lt;span class=&quot;hl-function&quot;&gt;ends_with&lt;/span&gt;(s: []&lt;span class=&quot;hl-keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;hl-type&quot;&gt;u8&lt;/span&gt;, suffix: []&lt;span class=&quot;hl-keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;hl-type&quot;&gt;u8&lt;/span&gt;) -&amp;gt; &lt;span class=&quot;hl-type&quot;&gt;bool&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Answers whether &lt;code&gt;s&lt;/code&gt; ends with &lt;code&gt;suffix&lt;/code&gt;. The mirror of &lt;code&gt;starts_with&lt;/code&gt;, and it
treats an empty suffix the same way.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Parameter&lt;/th&gt;&lt;th&gt;Type&lt;/th&gt;&lt;th&gt;Description&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;s&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;[]const u8&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the bytes to test&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;suffix&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;[]const u8&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the suffix to look for&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;Returns&lt;/strong&gt; &lt;code&gt;bool&lt;/code&gt; — &lt;code&gt;true&lt;/code&gt; when &lt;code&gt;s&lt;/code&gt; ends with &lt;code&gt;suffix&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&quot;find&quot;&gt;&lt;code&gt;find&lt;/code&gt;&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-sysl&quot;&gt;&lt;span class=&quot;hl-function&quot;&gt;find&lt;/span&gt;(haystack: []&lt;span class=&quot;hl-keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;hl-type&quot;&gt;u8&lt;/span&gt;, needle: []&lt;span class=&quot;hl-keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;hl-type&quot;&gt;u8&lt;/span&gt;) -&amp;gt; &lt;span class=&quot;hl-type&quot;&gt;Option&lt;/span&gt;[&lt;span class=&quot;hl-type&quot;&gt;usize&lt;/span&gt;]&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Answers the byte offset of the first occurrence of &lt;code&gt;needle&lt;/code&gt; in &lt;code&gt;haystack&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The offset is in &lt;strong&gt;bytes&lt;/strong&gt;, not characters — a needle found after a
three-byte character is at offset 3. Nothing here decodes UTF-8, which is what
lets the module make no allocation and ask for no capability.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Parameter&lt;/th&gt;&lt;th&gt;Type&lt;/th&gt;&lt;th&gt;Description&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;haystack&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;[]const u8&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the bytes to search&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;needle&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;[]const u8&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the bytes to search for&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;Returns&lt;/strong&gt; &lt;code&gt;Option[usize]&lt;/code&gt; — &lt;code&gt;Some(i)&lt;/code&gt; where &lt;code&gt;i&lt;/code&gt; is the offset of the first
occurrence, or &lt;code&gt;None&lt;/code&gt; when &lt;code&gt;needle&lt;/code&gt; does not occur. An empty needle occurs at
offset 0.&lt;/p&gt;
&lt;h3 id=&quot;split_once&quot;&gt;&lt;code&gt;split_once&lt;/code&gt;&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-sysl&quot;&gt;&lt;span class=&quot;hl-function&quot;&gt;split_once&lt;/span&gt;(s: []&lt;span class=&quot;hl-keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;hl-type&quot;&gt;u8&lt;/span&gt;, sep: []&lt;span class=&quot;hl-keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;hl-type&quot;&gt;u8&lt;/span&gt;) -&amp;gt; &lt;span class=&quot;hl-type&quot;&gt;Option&lt;/span&gt;[([]&lt;span class=&quot;hl-keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;hl-type&quot;&gt;u8&lt;/span&gt;, []&lt;span class=&quot;hl-keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;hl-type&quot;&gt;u8&lt;/span&gt;)]&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Splits &lt;code&gt;s&lt;/code&gt; at the first occurrence of &lt;code&gt;sep&lt;/code&gt; and answers the two halves, neither
of which contains the separator.&lt;/p&gt;
&lt;p&gt;Both halves are slices &lt;strong&gt;of &lt;code&gt;s&lt;/code&gt;&lt;/strong&gt;, so they live exactly as long as it does and
cost nothing to produce. Splitting &lt;code&gt;&amp;quot;key=value=more&amp;quot;&lt;/code&gt; on &lt;code&gt;&amp;quot;=&amp;quot;&lt;/code&gt; answers
&lt;code&gt;(&amp;quot;key&amp;quot;, &amp;quot;value=more&amp;quot;)&lt;/code&gt; — the separator is found once, not greedily.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Parameter&lt;/th&gt;&lt;th&gt;Type&lt;/th&gt;&lt;th&gt;Description&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;s&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;[]const u8&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the bytes to split&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;sep&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;[]const u8&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the separator to split at&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;Returns&lt;/strong&gt; &lt;code&gt;Option[([]const u8, []const u8)]&lt;/code&gt; — the two halves, or &lt;code&gt;None&lt;/code&gt; when
&lt;code&gt;sep&lt;/code&gt; does not occur in &lt;code&gt;s&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&quot;trim&quot;&gt;&lt;code&gt;trim&lt;/code&gt;&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-sysl&quot;&gt;&lt;span class=&quot;hl-function&quot;&gt;trim&lt;/span&gt;(s: []&lt;span class=&quot;hl-keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;hl-type&quot;&gt;u8&lt;/span&gt;) -&amp;gt; []&lt;span class=&quot;hl-keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;hl-type&quot;&gt;u8&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Answers &lt;code&gt;s&lt;/code&gt; without leading or trailing ASCII whitespace.&lt;/p&gt;
&lt;p&gt;Whitespace here is space, tab, carriage return, line feed, form feed and
vertical tab — the set C’s &lt;code&gt;isspace&lt;/code&gt; uses in the C locale. Unicode whitespace
is deliberately not recognised, for the same reason &lt;code&gt;find&lt;/code&gt; does not decode: it
would make the module need a table.&lt;/p&gt;
&lt;div class=&quot;callout callout-note&quot;&gt;
  &lt;div class=&quot;callout-title&quot;&gt;Note&lt;/div&gt;
  &lt;div class=&quot;callout-content&quot;&gt;
    &lt;p&gt;A string that is entirely whitespace trims to an empty slice, not to &lt;code&gt;None&lt;/code&gt;.&lt;/p&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Parameter&lt;/th&gt;&lt;th&gt;Type&lt;/th&gt;&lt;th&gt;Description&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;s&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;[]const u8&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the bytes to trim&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;Returns&lt;/strong&gt; &lt;code&gt;[]const u8&lt;/code&gt; — a sub-slice of &lt;code&gt;s&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;types&quot;&gt;Types&lt;/h2&gt;
&lt;h3 id=&quot;cursor&quot;&gt;&lt;code&gt;Cursor&lt;/code&gt;&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-sysl&quot;&gt;&lt;span class=&quot;hl-keyword&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;hl-type&quot;&gt;Cursor&lt;/span&gt;
    src: []&lt;span class=&quot;hl-keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;hl-type&quot;&gt;u8&lt;/span&gt;
    pos: &lt;span class=&quot;hl-type&quot;&gt;usize&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A position within a byte slice, for walking one token at a time.&lt;/p&gt;
&lt;p&gt;A cursor borrows its source rather than owning it, so it must not outlive the
slice it was made from. Reading past the end is not an error — the reading
members answer &lt;code&gt;None&lt;/code&gt; instead.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Field&lt;/th&gt;&lt;th&gt;Type&lt;/th&gt;&lt;th&gt;Description&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;src&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;[]const u8&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the bytes being walked&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;pos&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;usize&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the current offset, in bytes, from the start of &lt;code&gt;src&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h3 id=&quot;utf8error&quot;&gt;&lt;code&gt;Utf8Error&lt;/code&gt;&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-sysl&quot;&gt;&lt;span class=&quot;hl-keyword&quot;&gt;enum&lt;/span&gt; &lt;span class=&quot;hl-type&quot;&gt;Utf8Error&lt;/span&gt;
    &lt;span class=&quot;hl-function&quot;&gt;Truncated&lt;/span&gt;(at: &lt;span class=&quot;hl-type&quot;&gt;usize&lt;/span&gt;)
    &lt;span class=&quot;hl-function&quot;&gt;Invalid&lt;/span&gt;(at: &lt;span class=&quot;hl-type&quot;&gt;usize&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;What went wrong while decoding, and where.&lt;/p&gt;
&lt;p&gt;Both variants carry the byte offset at which the problem was found, so a caller
can report the position without walking the input a second time.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Variant&lt;/th&gt;&lt;th&gt;Payload&lt;/th&gt;&lt;th&gt;Description&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Truncated&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;at: usize&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the input ended part-way through a character&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Invalid&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;at: usize&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the byte at this offset can begin no character&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id=&quot;traits&quot;&gt;Traits&lt;/h2&gt;
&lt;h3 id=&quot;scan&quot;&gt;&lt;code&gt;Scan&lt;/code&gt;&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-sysl&quot;&gt;&lt;span class=&quot;hl-keyword&quot;&gt;trait&lt;/span&gt; &lt;span class=&quot;hl-type&quot;&gt;Scan&lt;/span&gt;
    &lt;span class=&quot;hl-keyword&quot;&gt;type&lt;/span&gt; &lt;span class=&quot;hl-type&quot;&gt;Item&lt;/span&gt;
    &lt;span class=&quot;hl-function&quot;&gt;next&lt;/span&gt;(&lt;span class=&quot;hl-variable&quot;&gt;self&lt;/span&gt;) -&amp;gt; &lt;span class=&quot;hl-type&quot;&gt;Option&lt;/span&gt;[&lt;span class=&quot;hl-type&quot;&gt;Self&lt;/span&gt;::&lt;span class=&quot;hl-type&quot;&gt;Item&lt;/span&gt;]&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;What a thing that yields items one at a time has to provide.&lt;/p&gt;
&lt;p&gt;Implemented by &lt;code&gt;Cursor&lt;/code&gt;, and by anything else that walks a source without
owning it. The associated &lt;code&gt;Item&lt;/code&gt; is what settles what a walk yields, so one
trait covers a cursor over bytes and a cursor over lines.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Members&lt;/strong&gt;&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Member&lt;/th&gt;&lt;th&gt;Signature&lt;/th&gt;&lt;th&gt;Description&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;Item&lt;/code&gt;&lt;/td&gt;&lt;td&gt;associated type&lt;/td&gt;&lt;td&gt;what each step yields&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;next&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;(self) -&amp;gt; Option[Self::Item]&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the next item, or &lt;code&gt;None&lt;/code&gt; at the end&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;</content>
  </entry>
  <entry>
    <title>bristle.buf</title>
    <link href="https://juicer.build/themes/juicerapi/demo/buf/"/>
    <id>https://juicer.build/themes/juicerapi/demo/buf/</id>
    <updated>2026-08-25T22:28:57.485307746Z</updated>
    <summary>A growable byte buffer with an explicit capacity, for building output without a copy per append.</summary>
    <content type="html">&lt;h2 id=&quot;index&quot;&gt;Index&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;#buf&quot;&gt;&lt;code&gt;buf&lt;/code&gt;&lt;/a&gt; &lt;a href=&quot;#with_capacity&quot;&gt;&lt;code&gt;with_capacity&lt;/code&gt;&lt;/a&gt; &lt;a href=&quot;#push&quot;&gt;&lt;code&gt;push&lt;/code&gt;&lt;/a&gt;
&lt;a href=&quot;#extend&quot;&gt;&lt;code&gt;extend&lt;/code&gt;&lt;/a&gt; &lt;a href=&quot;#as_slice&quot;&gt;&lt;code&gt;as_slice&lt;/code&gt;&lt;/a&gt; &lt;a href=&quot;#clear&quot;&gt;&lt;code&gt;clear&lt;/code&gt;&lt;/a&gt; &lt;a href=&quot;#buf-1&quot;&gt;&lt;code&gt;Buf&lt;/code&gt;&lt;/a&gt;
&lt;a href=&quot;#full&quot;&gt;&lt;code&gt;Full&lt;/code&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;functions&quot;&gt;Functions&lt;/h2&gt;
&lt;h3 id=&quot;buf&quot;&gt;&lt;code&gt;buf&lt;/code&gt;&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-sysl&quot;&gt;&lt;span class=&quot;hl-function&quot;&gt;buf&lt;/span&gt;() -&amp;gt; &lt;span class=&quot;hl-type&quot;&gt;Buf&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Answers an empty buffer that has allocated nothing yet.&lt;/p&gt;
&lt;p&gt;The first &lt;code&gt;push&lt;/code&gt; allocates. A buffer that is built and dropped without ever
being written to therefore costs no allocation at all, which is why this rather
than a capacity is the default constructor.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Returns&lt;/strong&gt; &lt;code&gt;Buf&lt;/code&gt; — an empty buffer with a capacity of zero.&lt;/p&gt;
&lt;h3 id=&quot;with_capacity&quot;&gt;&lt;code&gt;with_capacity&lt;/code&gt;&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-sysl&quot;&gt;&lt;span class=&quot;hl-function&quot;&gt;with_capacity&lt;/span&gt;(n: &lt;span class=&quot;hl-type&quot;&gt;usize&lt;/span&gt;) -&amp;gt; &lt;span class=&quot;hl-type&quot;&gt;Buf&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Answers an empty buffer with room for &lt;code&gt;n&lt;/code&gt; bytes already reserved.&lt;/p&gt;
&lt;p&gt;Reach for this when the size is known — building a line of known width, or
encoding a value whose bound the caller can compute. It turns a run of
doubling reallocations into one.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Parameter&lt;/th&gt;&lt;th&gt;Type&lt;/th&gt;&lt;th&gt;Description&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;n&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;usize&lt;/code&gt;&lt;/td&gt;&lt;td&gt;how many bytes to reserve&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;Returns&lt;/strong&gt; &lt;code&gt;Buf&lt;/code&gt; — an empty buffer whose capacity is at least &lt;code&gt;n&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&quot;push&quot;&gt;&lt;code&gt;push&lt;/code&gt;&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-sysl&quot;&gt;&lt;span class=&quot;hl-function&quot;&gt;push&lt;/span&gt;(&lt;span class=&quot;hl-variable&quot;&gt;self&lt;/span&gt;, b: &lt;span class=&quot;hl-type&quot;&gt;u8&lt;/span&gt;) -&amp;gt; &lt;span class=&quot;hl-type&quot;&gt;Result&lt;/span&gt;[&lt;span class=&quot;hl-type&quot;&gt;unit&lt;/span&gt;, &lt;span class=&quot;hl-type&quot;&gt;Full&lt;/span&gt;]&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Appends one byte, growing the buffer if it is full.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Parameter&lt;/th&gt;&lt;th&gt;Type&lt;/th&gt;&lt;th&gt;Description&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;self&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;&amp;amp;Buf&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the buffer to append to&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;b&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;u8&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the byte to append&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;Returns&lt;/strong&gt; &lt;code&gt;Result[unit, Full]&lt;/code&gt; — &lt;code&gt;Ok(())&lt;/code&gt;, or &lt;code&gt;Err(Full)&lt;/code&gt; when the allocator
refused. A refused push leaves the buffer exactly as it was.&lt;/p&gt;
&lt;h3 id=&quot;extend&quot;&gt;&lt;code&gt;extend&lt;/code&gt;&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-sysl&quot;&gt;&lt;span class=&quot;hl-function&quot;&gt;extend&lt;/span&gt;(&lt;span class=&quot;hl-variable&quot;&gt;self&lt;/span&gt;, bytes: []&lt;span class=&quot;hl-keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;hl-type&quot;&gt;u8&lt;/span&gt;) -&amp;gt; &lt;span class=&quot;hl-type&quot;&gt;Result&lt;/span&gt;[&lt;span class=&quot;hl-type&quot;&gt;unit&lt;/span&gt;, &lt;span class=&quot;hl-type&quot;&gt;Full&lt;/span&gt;]&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&quot;callout callout-warning&quot;&gt;
  &lt;div class=&quot;callout-title&quot;&gt;Warning&lt;/div&gt;
  &lt;div class=&quot;callout-content&quot;&gt;
    &lt;p&gt;A failed &lt;code&gt;extend&lt;/code&gt; is &lt;strong&gt;not&lt;/strong&gt; atomic — the bytes that fit are kept. Read the
length back if you need to know how far it got.&lt;/p&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Appends every byte of &lt;code&gt;bytes&lt;/code&gt;, growing once rather than once per byte.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Parameter&lt;/th&gt;&lt;th&gt;Type&lt;/th&gt;&lt;th&gt;Description&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;self&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;&amp;amp;Buf&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the buffer to append to&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;bytes&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;[]const u8&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the bytes to append&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;Returns&lt;/strong&gt; &lt;code&gt;Result[unit, Full]&lt;/code&gt; — &lt;code&gt;Ok(())&lt;/code&gt;, or &lt;code&gt;Err(Full)&lt;/code&gt; when the allocator
refused part-way.&lt;/p&gt;
&lt;h3 id=&quot;as_slice&quot;&gt;&lt;code&gt;as_slice&lt;/code&gt;&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-sysl&quot;&gt;&lt;span class=&quot;hl-function&quot;&gt;as_slice&lt;/span&gt;(&lt;span class=&quot;hl-variable&quot;&gt;self&lt;/span&gt;) -&amp;gt; []&lt;span class=&quot;hl-keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;hl-type&quot;&gt;u8&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Answers the written bytes as a slice, without copying them.&lt;/p&gt;
&lt;p&gt;The slice borrows the buffer’s storage, so it is invalidated by the next
&lt;code&gt;push&lt;/code&gt;, &lt;code&gt;extend&lt;/code&gt; or &lt;code&gt;clear&lt;/code&gt;. Hand it to a reader that finishes with it before
the buffer is touched again.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Parameter&lt;/th&gt;&lt;th&gt;Type&lt;/th&gt;&lt;th&gt;Description&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;self&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;&amp;amp;Buf&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the buffer to read&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;strong&gt;Returns&lt;/strong&gt; &lt;code&gt;[]const u8&lt;/code&gt; — the bytes written so far, in order.&lt;/p&gt;
&lt;h3 id=&quot;clear&quot;&gt;&lt;code&gt;clear&lt;/code&gt;&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-sysl&quot;&gt;&lt;span class=&quot;hl-function&quot;&gt;clear&lt;/span&gt;(&lt;span class=&quot;hl-variable&quot;&gt;self&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Forgets the written bytes and keeps the storage.&lt;/p&gt;
&lt;p&gt;The capacity is unchanged, which is the point: a buffer cleared between
iterations of a loop allocates once for the whole loop rather than once per
pass.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Parameter&lt;/th&gt;&lt;th&gt;Type&lt;/th&gt;&lt;th&gt;Description&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;self&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;&amp;amp;Buf&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the buffer to clear&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id=&quot;types&quot;&gt;Types&lt;/h2&gt;
&lt;h3 id=&quot;buf-1&quot;&gt;&lt;code&gt;Buf&lt;/code&gt;&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-sysl&quot;&gt;&lt;span class=&quot;hl-keyword&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;hl-type&quot;&gt;Buf&lt;/span&gt;
    ptr: &lt;span class=&quot;hl-keyword&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;hl-type&quot;&gt;u8&lt;/span&gt;
    len: &lt;span class=&quot;hl-type&quot;&gt;usize&lt;/span&gt;
    cap: &lt;span class=&quot;hl-type&quot;&gt;usize&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A growable byte buffer.&lt;/p&gt;
&lt;p&gt;The fields are private to the module; they are listed because a reader working
out the cost of an operation needs to know there are three of them and that
none is a length prefix stored with the data.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Field&lt;/th&gt;&lt;th&gt;Type&lt;/th&gt;&lt;th&gt;Description&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;ptr&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;*u8&lt;/code&gt;&lt;/td&gt;&lt;td&gt;the allocated storage, or null at capacity zero&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;len&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;usize&lt;/code&gt;&lt;/td&gt;&lt;td&gt;how many bytes have been written&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;cap&lt;/code&gt;&lt;/td&gt;&lt;td&gt;&lt;code&gt;usize&lt;/code&gt;&lt;/td&gt;&lt;td&gt;how many bytes &lt;code&gt;ptr&lt;/code&gt; has room for&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h3 id=&quot;full&quot;&gt;&lt;code&gt;Full&lt;/code&gt;&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-sysl&quot;&gt;&lt;span class=&quot;hl-keyword&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;hl-type&quot;&gt;Full&lt;/span&gt;
&lt;span class=&quot;hl-keyword&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;hl-type&quot;&gt; Full&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The allocator refused to grow the buffer.&lt;/p&gt;
&lt;p&gt;It carries nothing: there is one way for an append to fail and no detail a
caller could act on. A program that wants to distinguish &lt;em&gt;out of memory&lt;/em&gt; from
&lt;em&gt;over a configured ceiling&lt;/em&gt; wants two allocators, not two errors.&lt;/p&gt;</content>
  </entry>
</feed>
