pub struct Take<T> { }
Expand description
Reader adapter 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.
Returns the number of bytes that can be read before this instance will return EOF.
§NoteThis 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;
fn main() -> io::Result<()> {
let f = File::open("foo.txt")?;
let handle = f.take(5);
println!("limit: {}", handle.limit());
Ok(())
}
Source ð¬This is a nightly-only experimental API. (seek_io_take_position
#97227)
Returns the number of bytes read so far.
1.27.0 · SourceSets 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.
use std::io;
use std::io::prelude::*;
use std::fs::File;
fn main() -> io::Result<()> {
let f = File::open("foo.txt")?;
let mut handle = f.take(5);
handle.set_limit(10);
assert_eq!(handle.limit(), 10);
Ok(())
}
1.15.0 · Source
Consumes the Take
, returning the wrapped reader.
use std::io;
use std::io::prelude::*;
use std::fs::File;
fn main() -> io::Result<()> {
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();
Ok(())
}
1.20.0 · Source
Gets a 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 this Take
.
use std::io;
use std::io::prelude::*;
use std::fs::File;
fn main() -> io::Result<()> {
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();
Ok(())
}
1.20.0 · Source
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 this Take
.
use std::io;
use std::io::prelude::*;
use std::fs::File;
fn main() -> io::Result<()> {
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();
Ok(())
}
1.0.0 · Source§ Source§
Returns the contents of the internal buffer, filling it with more data, via
Read
methods, if empty.
Read more Source§Marks the given
amount
of additional bytes from the internal buffer as having been read. Subsequent calls to
read
only return bytes that have not been marked as read.
Read more Source§ ð¬This is a nightly-only experimental API. (buf_read_has_data_left
#86423)
Checks if there is any data left to be
read
.
Read more 1.0.0 · Source§Reads all bytes into
buf
until the delimiter
byte
or EOF is reached.
Read more 1.83.0 · Source§Skips all bytes until the delimiter
byte
or EOF is reached.
Read more 1.0.0 · Source§Reads all bytes until a newline (the
0xA
byte) is reached, and append them to the provided
String
buffer.
Read more 1.0.0 · Source§Returns an iterator over the contents of this reader split on the byte
byte
.
Read more 1.0.0 · Source§Returns an iterator over the lines of this reader.
Read more 1.0.0 · Source§ 1.0.0 · Source§ Source§Pull some bytes from this source into the specified buffer, returning how many bytes were read.
Read more Source§ ð¬This is a nightly-only experimental API. (read_buf
#78485)
Pull some bytes from this source into the specified buffer.
Read more 1.36.0 · Source§Like
read
, except that it reads into a slice of buffers.
Read more Source§ ð¬This is a nightly-only experimental API. (can_vector
#69941)
Determines if this
Read
er has an efficient
read_vectored
implementation.
Read more 1.0.0 · Source§Reads all bytes until EOF in this source, placing them into
buf
.
Read more 1.0.0 · Source§Reads all bytes until EOF in this source, appending them to
buf
.
Read more 1.6.0 · Source§Reads the exact number of bytes required to fill
buf
.
Read more Source§ ð¬This is a nightly-only experimental API. (read_buf
#78485)
Reads the exact number of bytes required to fill
cursor
.
Read more 1.0.0 · Source§Creates a âby referenceâ adaptor for this instance of
Read
.
Read more 1.0.0 · Source§ 1.0.0 · Source§Creates an adapter which will chain this stream with another.
Read more 1.0.0 · Source§Creates an adapter which will read at most
limit
bytes from it.
Read more 1.89.0 · Source§RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4