difftastic/rustdoc/bstr/io/trait.BufReadExt.html

218 lines
31 KiB
HTML

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<!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 extension trait for `std::io::BufRead` which provides convenience APIs for dealing with byte strings."><title>BufReadExt in bstr::io - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/SourceSerif4-Regular-46f98efaafac5295.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><link rel="stylesheet" href="../../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../../static.files/rustdoc-ac92e1bbe349e143.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="bstr" data-themes="" data-resource-suffix="" data-rustdoc-version="1.76.0 (07dca489a 2024-02-04)" data-channel="1.76.0" data-search-js="search-2b6ce74ff89ae146.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="../../static.files/storage-f2adc0d6ca4d09fb.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-305769736d49e732.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-feafe1bb7466e4bd.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-16x16-8b506e7a72182f1c.png"><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-2c020d218678b618.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">&#9776;</button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../bstr/index.html">bstr</a><span class="version">1.9.1</span></h2></div><h2 class="location"><a href="#">BufReadExt</a></h2><div class="sidebar-elems"><section><h3><a href="#provided-methods">Provided Methods</a></h3><ul class="block"><li><a href="#method.byte_lines">byte_lines</a></li><li><a href="#method.byte_records">byte_records</a></li><li><a href="#method.for_byte_line">for_byte_line</a></li><li><a href="#method.for_byte_line_with_terminator">for_byte_line_with_terminator</a></li><li><a href="#method.for_byte_record">for_byte_record</a></li><li><a href="#method.for_byte_record_with_terminator">for_byte_record_with_terminator</a></li></ul><h3><a href="#implementors">Implementors</a></h3></section><h2><a href="index.html">In bstr::io</a></h2></div></nav><div class="sidebar-resizer"></div>
<main><div class="width-limiter"><nav class="sub"><form class="search-form"><span></span><div id="sidebar-button" tabindex="-1"><a href="../../bstr/all.html" title="show sidebar"></a></div><input class="search-input" name="search" aria-label="Run search in the documentation" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"><div id="help-button" tabindex="-1"><a href="../../help.html" title="help">?</a></div><div id="settings-menu" tabindex="-1"><a href="../../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../../static.files/wheel-7b819b6101059cd0.svg"></a></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1>Trait <a href="../index.html">bstr</a>::<wbr><a href="index.html">io</a>::<wbr><a class="trait" href="#">BufReadExt</a><button id="copy-path" title="Copy item path to clipboard"><img src="../../static.files/clipboard-7571035ce49a181d.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="src" href="../../src/bstr/io.rs.html#19-345">source</a> · <button id="toggle-all-docs" title="collapse all docs">[<span>&#x2212;</span>]</button></span></div><pre class="rust item-decl"><code>pub trait BufReadExt: <a class="trait" href="https://doc.rust-lang.org/1.76.0/std/io/trait.BufRead.html" title="trait std::io::BufRead">BufRead</a> {
// Provided methods
fn <a href="#method.byte_lines" class="fn">byte_lines</a>(self) -&gt; <a class="struct" href="struct.ByteLines.html" title="struct bstr::io::ByteLines">ByteLines</a>&lt;Self&gt; <a href="#" class="tooltip" data-notable-ty="ByteLines&lt;Self&gt;"></a>
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
<span class="item-spacer"></span> fn <a href="#method.byte_records" class="fn">byte_records</a>(self, terminator: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.u8.html">u8</a>) -&gt; <a class="struct" href="struct.ByteRecords.html" title="struct bstr::io::ByteRecords">ByteRecords</a>&lt;Self&gt; <a href="#" class="tooltip" data-notable-ty="ByteRecords&lt;Self&gt;"></a>
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
<span class="item-spacer"></span> fn <a href="#method.for_byte_line" class="fn">for_byte_line</a>&lt;F&gt;(&amp;mut self, for_each_line: F) -&gt; <a class="type" href="https://doc.rust-lang.org/1.76.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.unit.html">()</a>&gt;
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&amp;[<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.u8.html">u8</a>]) -&gt; <a class="type" href="https://doc.rust-lang.org/1.76.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a>&gt;</span> { ... }
<span class="item-spacer"></span> fn <a href="#method.for_byte_record" class="fn">for_byte_record</a>&lt;F&gt;(
&amp;mut self,
terminator: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.u8.html">u8</a>,
for_each_record: F
) -&gt; <a class="type" href="https://doc.rust-lang.org/1.76.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.unit.html">()</a>&gt;
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&amp;[<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.u8.html">u8</a>]) -&gt; <a class="type" href="https://doc.rust-lang.org/1.76.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a>&gt;</span> { ... }
<span class="item-spacer"></span> fn <a href="#method.for_byte_line_with_terminator" class="fn">for_byte_line_with_terminator</a>&lt;F&gt;(
&amp;mut self,
for_each_line: F
) -&gt; <a class="type" href="https://doc.rust-lang.org/1.76.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.unit.html">()</a>&gt;
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&amp;[<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.u8.html">u8</a>]) -&gt; <a class="type" href="https://doc.rust-lang.org/1.76.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a>&gt;</span> { ... }
<span class="item-spacer"></span> fn <a href="#method.for_byte_record_with_terminator" class="fn">for_byte_record_with_terminator</a>&lt;F&gt;(
&amp;mut self,
terminator: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.u8.html">u8</a>,
for_each_record: F
) -&gt; <a class="type" href="https://doc.rust-lang.org/1.76.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.unit.html">()</a>&gt;
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&amp;[<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.u8.html">u8</a>]) -&gt; <a class="type" href="https://doc.rust-lang.org/1.76.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a>&gt;</span> { ... }
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>An extension trait for
<a href="https://doc.rust-lang.org/std/io/trait.BufRead.html"><code>std::io::BufRead</code></a>
which provides convenience APIs for dealing with byte strings.</p>
</div></details><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.byte_lines" class="method"><a class="src rightside" href="../../src/bstr/io.rs.html#53-58">source</a><h4 class="code-header">fn <a href="#method.byte_lines" class="fn">byte_lines</a>(self) -&gt; <a class="struct" href="struct.ByteLines.html" title="struct bstr::io::ByteLines">ByteLines</a>&lt;Self&gt; <a href="#" class="tooltip" data-notable-ty="ByteLines&lt;Self&gt;"></a><div class="where">where
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><div class="docblock"><p>Returns an iterator over the lines of this reader, where each line
is represented as a byte string.</p>
<p>Each item yielded by this iterator is a <code>io::Result&lt;Vec&lt;u8&gt;&gt;</code>, where
an error is yielded if there was a problem reading from the underlying
reader.</p>
<p>On success, the next line in the iterator is returned. The line does
<em>not</em> contain a trailing <code>\n</code> or <code>\r\n</code>.</p>
<h5 id="examples"><a href="#examples">Examples</a></h5>
<p>Basic usage:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::io;
<span class="kw">use </span>bstr::io::BufReadExt;
<span class="kw">let </span><span class="kw-2">mut </span>cursor = io::Cursor::new(<span class="string">b"lorem\nipsum\r\ndolor"</span>);
<span class="kw">let </span><span class="kw-2">mut </span>lines = <span class="macro">vec!</span>[];
<span class="kw">for </span>result <span class="kw">in </span>cursor.byte_lines() {
<span class="kw">let </span>line = result<span class="question-mark">?</span>;
lines.push(line);
}
<span class="macro">assert_eq!</span>(lines.len(), <span class="number">3</span>);
<span class="macro">assert_eq!</span>(lines[<span class="number">0</span>], <span class="string">"lorem"</span>.as_bytes());
<span class="macro">assert_eq!</span>(lines[<span class="number">1</span>], <span class="string">"ipsum"</span>.as_bytes());
<span class="macro">assert_eq!</span>(lines[<span class="number">2</span>], <span class="string">"dolor"</span>.as_bytes());</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.byte_records" class="method"><a class="src rightside" href="../../src/bstr/io.rs.html#96-101">source</a><h4 class="code-header">fn <a href="#method.byte_records" class="fn">byte_records</a>(self, terminator: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.u8.html">u8</a>) -&gt; <a class="struct" href="struct.ByteRecords.html" title="struct bstr::io::ByteRecords">ByteRecords</a>&lt;Self&gt; <a href="#" class="tooltip" data-notable-ty="ByteRecords&lt;Self&gt;"></a><div class="where">where
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><div class="docblock"><p>Returns an iterator over byte-terminated records of this reader, where
each record is represented as a byte string.</p>
<p>Each item yielded by this iterator is a <code>io::Result&lt;Vec&lt;u8&gt;&gt;</code>, where
an error is yielded if there was a problem reading from the underlying
reader.</p>
<p>On success, the next record in the iterator is returned. The record
does <em>not</em> contain its trailing terminator.</p>
<p>Note that calling <code>byte_records(b'\n')</code> differs from <code>byte_lines()</code> in
that it has no special handling for <code>\r</code>.</p>
<h5 id="examples-1"><a href="#examples-1">Examples</a></h5>
<p>Basic usage:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::io;
<span class="kw">use </span>bstr::io::BufReadExt;
<span class="kw">let </span><span class="kw-2">mut </span>cursor = io::Cursor::new(<span class="string">b"lorem\x00ipsum\x00dolor"</span>);
<span class="kw">let </span><span class="kw-2">mut </span>records = <span class="macro">vec!</span>[];
<span class="kw">for </span>result <span class="kw">in </span>cursor.byte_records(<span class="string">b'\x00'</span>) {
<span class="kw">let </span>record = result<span class="question-mark">?</span>;
records.push(record);
}
<span class="macro">assert_eq!</span>(records.len(), <span class="number">3</span>);
<span class="macro">assert_eq!</span>(records[<span class="number">0</span>], <span class="string">"lorem"</span>.as_bytes());
<span class="macro">assert_eq!</span>(records[<span class="number">1</span>], <span class="string">"ipsum"</span>.as_bytes());
<span class="macro">assert_eq!</span>(records[<span class="number">2</span>], <span class="string">"dolor"</span>.as_bytes());</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.for_byte_line" class="method"><a class="src rightside" href="../../src/bstr/io.rs.html#139-147">source</a><h4 class="code-header">fn <a href="#method.for_byte_line" class="fn">for_byte_line</a>&lt;F&gt;(&amp;mut self, for_each_line: F) -&gt; <a class="type" href="https://doc.rust-lang.org/1.76.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.unit.html">()</a>&gt;<div class="where">where
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&amp;[<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.u8.html">u8</a>]) -&gt; <a class="type" href="https://doc.rust-lang.org/1.76.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a>&gt;,</div></h4></section></summary><div class="docblock"><p>Executes the given closure on each line in the underlying reader.</p>
<p>If the closure returns an error (or if the underlying reader returns an
error), then iteration is stopped and the error is returned. If false
is returned, then iteration is stopped and no error is returned.</p>
<p>The closure given is called on exactly the same values as yielded by
the <a href="trait.BufReadExt.html#method.byte_lines"><code>byte_lines</code></a>
iterator. Namely, lines do <em>not</em> contain trailing <code>\n</code> or <code>\r\n</code> bytes.</p>
<p>This routine is useful for iterating over lines as quickly as
possible. Namely, a single allocation is reused for each line.</p>
<h5 id="examples-2"><a href="#examples-2">Examples</a></h5>
<p>Basic usage:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::io;
<span class="kw">use </span>bstr::io::BufReadExt;
<span class="kw">let </span><span class="kw-2">mut </span>cursor = io::Cursor::new(<span class="string">b"lorem\nipsum\r\ndolor"</span>);
<span class="kw">let </span><span class="kw-2">mut </span>lines = <span class="macro">vec!</span>[];
cursor.for_byte_line(|line| {
lines.push(line.to_vec());
<span class="prelude-val">Ok</span>(<span class="bool-val">true</span>)
})<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(lines.len(), <span class="number">3</span>);
<span class="macro">assert_eq!</span>(lines[<span class="number">0</span>], <span class="string">"lorem"</span>.as_bytes());
<span class="macro">assert_eq!</span>(lines[<span class="number">1</span>], <span class="string">"ipsum"</span>.as_bytes());
<span class="macro">assert_eq!</span>(lines[<span class="number">2</span>], <span class="string">"dolor"</span>.as_bytes());</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.for_byte_record" class="method"><a class="src rightside" href="../../src/bstr/io.rs.html#186-198">source</a><h4 class="code-header">fn <a href="#method.for_byte_record" class="fn">for_byte_record</a>&lt;F&gt;(
&amp;mut self,
terminator: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.u8.html">u8</a>,
for_each_record: F
) -&gt; <a class="type" href="https://doc.rust-lang.org/1.76.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.unit.html">()</a>&gt;<div class="where">where
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&amp;[<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.u8.html">u8</a>]) -&gt; <a class="type" href="https://doc.rust-lang.org/1.76.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a>&gt;,</div></h4></section></summary><div class="docblock"><p>Executes the given closure on each byte-terminated record in the
underlying reader.</p>
<p>If the closure returns an error (or if the underlying reader returns an
error), then iteration is stopped and the error is returned. If false
is returned, then iteration is stopped and no error is returned.</p>
<p>The closure given is called on exactly the same values as yielded by
the <a href="trait.BufReadExt.html#method.byte_records"><code>byte_records</code></a>
iterator. Namely, records do <em>not</em> contain a trailing terminator byte.</p>
<p>This routine is useful for iterating over records as quickly as
possible. Namely, a single allocation is reused for each record.</p>
<h5 id="examples-3"><a href="#examples-3">Examples</a></h5>
<p>Basic usage:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::io;
<span class="kw">use </span>bstr::io::BufReadExt;
<span class="kw">let </span><span class="kw-2">mut </span>cursor = io::Cursor::new(<span class="string">b"lorem\x00ipsum\x00dolor"</span>);
<span class="kw">let </span><span class="kw-2">mut </span>records = <span class="macro">vec!</span>[];
cursor.for_byte_record(<span class="string">b'\x00'</span>, |record| {
records.push(record.to_vec());
<span class="prelude-val">Ok</span>(<span class="bool-val">true</span>)
})<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(records.len(), <span class="number">3</span>);
<span class="macro">assert_eq!</span>(records[<span class="number">0</span>], <span class="string">"lorem"</span>.as_bytes());
<span class="macro">assert_eq!</span>(records[<span class="number">1</span>], <span class="string">"ipsum"</span>.as_bytes());
<span class="macro">assert_eq!</span>(records[<span class="number">2</span>], <span class="string">"dolor"</span>.as_bytes());</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.for_byte_line_with_terminator" class="method"><a class="src rightside" href="../../src/bstr/io.rs.html#240-249">source</a><h4 class="code-header">fn <a href="#method.for_byte_line_with_terminator" class="fn">for_byte_line_with_terminator</a>&lt;F&gt;(&amp;mut self, for_each_line: F) -&gt; <a class="type" href="https://doc.rust-lang.org/1.76.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.unit.html">()</a>&gt;<div class="where">where
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&amp;[<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.u8.html">u8</a>]) -&gt; <a class="type" href="https://doc.rust-lang.org/1.76.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a>&gt;,</div></h4></section></summary><div class="docblock"><p>Executes the given closure on each line in the underlying reader.</p>
<p>If the closure returns an error (or if the underlying reader returns an
error), then iteration is stopped and the error is returned. If false
is returned, then iteration is stopped and no error is returned.</p>
<p>Unlike
<a href="trait.BufReadExt.html#method.for_byte_line"><code>for_byte_line</code></a>,
the lines given to the closure <em>do</em> include the line terminator, if one
exists.</p>
<p>This routine is useful for iterating over lines as quickly as
possible. Namely, a single allocation is reused for each line.</p>
<p>This is identical to <code>for_byte_record_with_terminator</code> with a
terminator of <code>\n</code>.</p>
<h5 id="examples-4"><a href="#examples-4">Examples</a></h5>
<p>Basic usage:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::io;
<span class="kw">use </span>bstr::io::BufReadExt;
<span class="kw">let </span><span class="kw-2">mut </span>cursor = io::Cursor::new(<span class="string">b"lorem\nipsum\r\ndolor"</span>);
<span class="kw">let </span><span class="kw-2">mut </span>lines = <span class="macro">vec!</span>[];
cursor.for_byte_line_with_terminator(|line| {
lines.push(line.to_vec());
<span class="prelude-val">Ok</span>(<span class="bool-val">true</span>)
})<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(lines.len(), <span class="number">3</span>);
<span class="macro">assert_eq!</span>(lines[<span class="number">0</span>], <span class="string">"lorem\n"</span>.as_bytes());
<span class="macro">assert_eq!</span>(lines[<span class="number">1</span>], <span class="string">"ipsum\r\n"</span>.as_bytes());
<span class="macro">assert_eq!</span>(lines[<span class="number">2</span>], <span class="string">"dolor"</span>.as_bytes());</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.for_byte_record_with_terminator" class="method"><a class="src rightside" href="../../src/bstr/io.rs.html#289-344">source</a><h4 class="code-header">fn <a href="#method.for_byte_record_with_terminator" class="fn">for_byte_record_with_terminator</a>&lt;F&gt;(
&amp;mut self,
terminator: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.u8.html">u8</a>,
for_each_record: F
) -&gt; <a class="type" href="https://doc.rust-lang.org/1.76.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.unit.html">()</a>&gt;<div class="where">where
Self: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&amp;[<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.u8.html">u8</a>]) -&gt; <a class="type" href="https://doc.rust-lang.org/1.76.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a>&gt;,</div></h4></section></summary><div class="docblock"><p>Executes the given closure on each byte-terminated record in the
underlying reader.</p>
<p>If the closure returns an error (or if the underlying reader returns an
error), then iteration is stopped and the error is returned. If false
is returned, then iteration is stopped and no error is returned.</p>
<p>Unlike
<a href="trait.BufReadExt.html#method.for_byte_record"><code>for_byte_record</code></a>,
the lines given to the closure <em>do</em> include the record terminator, if
one exists.</p>
<p>This routine is useful for iterating over records as quickly as
possible. Namely, a single allocation is reused for each record.</p>
<h5 id="examples-5"><a href="#examples-5">Examples</a></h5>
<p>Basic usage:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::io;
<span class="kw">use </span>bstr::{io::BufReadExt, B};
<span class="kw">let </span><span class="kw-2">mut </span>cursor = io::Cursor::new(<span class="string">b"lorem\x00ipsum\x00dolor"</span>);
<span class="kw">let </span><span class="kw-2">mut </span>records = <span class="macro">vec!</span>[];
cursor.for_byte_record_with_terminator(<span class="string">b'\x00'</span>, |record| {
records.push(record.to_vec());
<span class="prelude-val">Ok</span>(<span class="bool-val">true</span>)
})<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(records.len(), <span class="number">3</span>);
<span class="macro">assert_eq!</span>(records[<span class="number">0</span>], B(<span class="string">b"lorem\x00"</span>));
<span class="macro">assert_eq!</span>(records[<span class="number">1</span>], B(<span class="string">"ipsum\x00"</span>));
<span class="macro">assert_eq!</span>(records[<span class="number">2</span>], B(<span class="string">"dolor"</span>));</code></pre></div>
</div></details></div><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"><section id="impl-BufReadExt-for-B" class="impl"><a class="src rightside" href="../../src/bstr/io.rs.html#347">source</a><a href="#impl-BufReadExt-for-B" class="anchor">§</a><h3 class="code-header">impl&lt;B: <a class="trait" href="https://doc.rust-lang.org/1.76.0/std/io/trait.BufRead.html" title="trait std::io::BufRead">BufRead</a>&gt; <a class="trait" href="trait.BufReadExt.html" title="trait bstr::io::BufReadExt">BufReadExt</a> for B</h3></section></div><script src="../../trait.impl/bstr/io/trait.BufReadExt.js" async></script><script type="text/json" id="notable-traits-data">{"ByteLines<Self>":"<h3>Notable traits for <code><a class=\"struct\" href=\"struct.ByteLines.html\" title=\"struct bstr::io::ByteLines\">ByteLines</a>&lt;B&gt;</code></h3><pre><code><div class=\"where\">impl&lt;B: <a class=\"trait\" href=\"https://doc.rust-lang.org/1.76.0/std/io/trait.BufRead.html\" title=\"trait std::io::BufRead\">BufRead</a>&gt; <a class=\"trait\" href=\"https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html\" title=\"trait core::iter::traits::iterator::Iterator\">Iterator</a> for <a class=\"struct\" href=\"struct.ByteLines.html\" title=\"struct bstr::io::ByteLines\">ByteLines</a>&lt;B&gt;</div><div class=\"where\"> type <a href=\"https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item\" class=\"associatedtype\">Item</a> = <a class=\"type\" href=\"https://doc.rust-lang.org/1.76.0/std/io/error/type.Result.html\" title=\"type std::io::error::Result\">Result</a>&lt;<a class=\"struct\" href=\"https://doc.rust-lang.org/1.76.0/alloc/vec/struct.Vec.html\" title=\"struct alloc::vec::Vec\">Vec</a>&lt;<a class=\"primitive\" href=\"https://doc.rust-lang.org/1.76.0/std/primitive.u8.html\">u8</a>&gt;&gt;;</div>","ByteRecords<Self>":"<h3>Notable traits for <code><a class=\"struct\" href=\"struct.ByteRecords.html\" title=\"struct bstr::io::ByteRecords\">ByteRecords</a>&lt;B&gt;</code></h3><pre><code><div class=\"where\">impl&lt;B: <a class=\"trait\" href=\"https://doc.rust-lang.org/1.76.0/std/io/trait.BufRead.html\" title=\"trait std::io::BufRead\">BufRead</a>&gt; <a class=\"trait\" href=\"https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html\" title=\"trait core::iter::traits::iterator::Iterator\">Iterator</a> for <a class=\"struct\" href=\"struct.ByteRecords.html\" title=\"struct bstr::io::ByteRecords\">ByteRecords</a>&lt;B&gt;</div><div class=\"where\"> type <a href=\"https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item\" class=\"associatedtype\">Item</a> = <a class=\"type\" href=\"https://doc.rust-lang.org/1.76.0/std/io/error/type.Result.html\" title=\"type std::io::error::Result\">Result</a>&lt;<a class=\"struct\" href=\"https://doc.rust-lang.org/1.76.0/alloc/vec/struct.Vec.html\" title=\"struct alloc::vec::Vec\">Vec</a>&lt;<a class=\"primitive\" href=\"https://doc.rust-lang.org/1.76.0/std/primitive.u8.html\">u8</a>&gt;&gt;;</div>"}</script></section></div></main></body></html>