std::io::Take - Rust (original) (raw)
Struct std::io::Take1.0.0 [−] [src]
pub struct Take { /* fields omitted */ }
Reader adaptor which limits the bytes read from an underlying reader.
This struct is generally created by calling take on a reader. Please see the documentation of take for more details.
impl<T> [Take](../../std/io/struct.Take.html "struct std::io::Take")<T>
[src]
pub fn [limit](#method.limit)(&self) -> [u64](../primitive.u64.html)
[src]
Returns the number of bytes that can be read before this instance will return EOF.
This instance may reach EOF
after reading fewer bytes than indicated by this method if the underlying Read instance reaches EOF.
use std::io; use std::io::prelude::*; use std::fs::File;
let f = File::open("foo.txt")?;
let handle = f.take(5);
println!("limit: {}", handle.limit());Run
pub fn [set_limit](#method.set%5Flimit)(&mut self, limit: [u64](../primitive.u64.html))
[src]
🔬 This is a nightly-only experimental API. (take_set_limit
#42781)
Sets the number of bytes that can be read before this instance will return EOF. This is the same as constructing a new Take
instance, so the amount of bytes read and the previous limit value don't matter when calling this method.
#![feature(take_set_limit)] use std::io; use std::io::prelude::*; use std::fs::File;
let f = File::open("foo.txt")?;
let mut handle = f.take(5); handle.set_limit(10);
assert_eq!(handle.limit(), 10);Run
pub fn [into_inner](#method.into%5Finner)(self) -> T
1.15.0
Consumes the Take
, returning the wrapped reader.
use std::io; use std::io::prelude::*; use std::fs::File;
let mut file = File::open("foo.txt")?;
let mut buffer = [0; 5]; let mut handle = file.take(5); handle.read(&mut buffer)?;
let file = handle.into_inner();Run
pub fn [get_ref](#method.get%5Fref)(&self) -> [&](../primitive.reference.html)T
1.20.0
Gets a reference to the underlying reader.
use std::io; use std::io::prelude::*; use std::fs::File;
let mut file = File::open("foo.txt")?;
let mut buffer = [0; 5]; let mut handle = file.take(5); handle.read(&mut buffer)?;
let file = handle.get_ref();Run
pub fn [get_mut](#method.get%5Fmut)(&mut self) -> [&mut ](../primitive.reference.html)T
1.20.0
Gets a mutable reference to the underlying reader.
Care should be taken to avoid modifying the internal I/O state of the underlying reader as doing so may corrupt the internal limit of thisTake
.
use std::io; use std::io::prelude::*; use std::fs::File;
let mut file = File::open("foo.txt")?;
let mut buffer = [0; 5]; let mut handle = file.take(5); handle.read(&mut buffer)?;
let file = handle.get_mut();Run
impl<T: [Debug](../../std/fmt/trait.Debug.html "trait std::fmt::Debug")> [Debug](../../std/fmt/trait.Debug.html "trait std::fmt::Debug") for [Take](../../std/io/struct.Take.html "struct std::io::Take")<T>
[src]
impl<T: [Read](../../std/io/trait.Read.html "trait std::io::Read")> [Read](../../std/io/trait.Read.html "trait std::io::Read") for [Take](../../std/io/struct.Take.html "struct std::io::Take")<T>
[src]
fn [read](../../std/io/trait.Read.html#tymethod.read)(&mut self, buf: [&mut [](../primitive.slice.html)[u8](../primitive.u8.html)[]](../primitive.slice.html)) -> [Result](../../std/io/type.Result.html "type std::io::Result")<[usize](../primitive.usize.html)>
[src]
Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more
unsafe fn [initializer](../../std/io/trait.Read.html#method.initializer)(&self) -> [Initializer](../../std/io/struct.Initializer.html "struct std::io::Initializer")
[src]
🔬 This is a nightly-only experimental API. (read_initializer
#42788)
Determines if this Read
er can work with buffers of uninitialized memory. Read more
fn [read_to_end](../../std/io/trait.Read.html#method.read%5Fto%5Fend)(&mut self, buf: &mut [Vec](../../std/vec/struct.Vec.html "struct std::vec::Vec")<[u8](../primitive.u8.html)>) -> [Result](../../std/io/type.Result.html "type std::io::Result")<[usize](../primitive.usize.html)>
[src]
Read all bytes until EOF in this source, placing them into buf
. Read more
fn [read_to_string](../../std/io/trait.Read.html#method.read%5Fto%5Fstring)(&mut self, buf: &mut [String](../../std/string/struct.String.html "struct std:🧵:String")) -> [Result](../../std/io/type.Result.html "type std::io::Result")<[usize](../primitive.usize.html)>
[src]
Read all bytes until EOF in this source, appending them to buf
. Read more
fn [read_exact](../../std/io/trait.Read.html#method.read%5Fexact)(&mut self, buf: [&mut [](../primitive.slice.html)[u8](../primitive.u8.html)[]](../primitive.slice.html)) -> [Result](../../std/io/type.Result.html "type std::io::Result")<[()](../primitive.unit.html)>
1.6.0
Read the exact number of bytes required to fill buf
. Read more
`fn by_ref(&mut self) -> &mut Self where
Creates a "by reference" adaptor for this instance of Read
. Read more
ⓘImportant traits for Bytes
fn [bytes](../../std/io/trait.Read.html#method.bytes)(self) -> [Bytes](../../std/io/struct.Bytes.html "struct std::io::Bytes")<Self> where Self: [Sized](../../std/marker/trait.Sized.html "trait std:📑:Sized"),
[src]
Transforms this Read
instance to an [Iterator
] over its bytes. Read more
ⓘImportant traits for Chars
fn [chars](../../std/io/trait.Read.html#method.chars)(self) -> [Chars](../../std/io/struct.Chars.html "struct std::io::Chars")<Self> where Self: [Sized](../../std/marker/trait.Sized.html "trait std:📑:Sized"),
[src]
🔬 This is a nightly-only experimental API. (io
#27802)
the semantics of a partial read/write of where errors happen is currently unclear and may change
Transforms this Read
instance to an [Iterator
] over [char
]s. Read more
ⓘImportant traits for Chain<T, U>
fn [chain](../../std/io/trait.Read.html#method.chain)<R: [Read](../../std/io/trait.Read.html "trait std::io::Read")>(self, next: R) -> [Chain](../../std/io/struct.Chain.html "struct std::io::Chain")<Self, R> where Self: [Sized](../../std/marker/trait.Sized.html "trait std:📑:Sized"),
[src]
Creates an adaptor which will chain this stream with another. Read more
ⓘImportant traits for Take
fn [take](../../std/io/trait.Read.html#method.take)(self, limit: [u64](../primitive.u64.html)) -> [Take](../../std/io/struct.Take.html "struct std::io::Take")<Self> where Self: [Sized](../../std/marker/trait.Sized.html "trait std:📑:Sized"),
[src]
Creates an adaptor which will read at most limit
bytes from it. Read more
impl<T: [BufRead](../../std/io/trait.BufRead.html "trait std::io::BufRead")> [BufRead](../../std/io/trait.BufRead.html "trait std::io::BufRead") for [Take](../../std/io/struct.Take.html "struct std::io::Take")<T>
[src]
fn [fill_buf](../../std/io/trait.BufRead.html#tymethod.fill%5Fbuf)(&mut self) -> [Result](../../std/io/type.Result.html "type std::io::Result")<[&[](../primitive.slice.html)[u8](../primitive.u8.html)[]](../primitive.slice.html)>
[src]
Fills the internal buffer of this object, returning the buffer contents. Read more
fn [consume](../../std/io/trait.BufRead.html#tymethod.consume)(&mut self, amt: [usize](../primitive.usize.html))
[src]
Tells this buffer that amt
bytes have been consumed from the buffer, so they should no longer be returned in calls to read
. Read more
fn [read_until](../../std/io/trait.BufRead.html#method.read%5Funtil)(&mut self, byte: [u8](../primitive.u8.html), buf: &mut [Vec](../../std/vec/struct.Vec.html "struct std::vec::Vec")<[u8](../primitive.u8.html)>) -> [Result](../../std/io/type.Result.html "type std::io::Result")<[usize](../primitive.usize.html)>
[src]
Read all bytes into buf
until the delimiter byte
or EOF is reached. Read more
fn [read_line](../../std/io/trait.BufRead.html#method.read%5Fline)(&mut self, buf: &mut [String](../../std/string/struct.String.html "struct std:🧵:String")) -> [Result](../../std/io/type.Result.html "type std::io::Result")<[usize](../primitive.usize.html)>
[src]
Read all bytes until a newline (the 0xA byte) is reached, and append them to the provided buffer. Read more
ⓘImportant traits for Split
fn [split](../../std/io/trait.BufRead.html#method.split)(self, byte: [u8](../primitive.u8.html)) -> [Split](../../std/io/struct.Split.html "struct std::io::Split")<Self> where Self: [Sized](../../std/marker/trait.Sized.html "trait std:📑:Sized"),
[src]
Returns an iterator over the contents of this reader split on the byte byte
. Read more
ⓘImportant traits for Lines
fn [lines](../../std/io/trait.BufRead.html#method.lines)(self) -> [Lines](../../std/io/struct.Lines.html "struct std::io::Lines")<Self> where Self: [Sized](../../std/marker/trait.Sized.html "trait std:📑:Sized"),
[src]
Returns an iterator over the lines of this reader. Read more