pub struct Chain<T, U> { /* private fields */ }
Implementations§
source§impl<T, U> Chain<T, U>
impl<T, U> Chain<T, U>
1.20.0 · sourcepub fn into_inner(self) -> (T, U)
pub fn into_inner(self) -> (T, U)
消耗 Chain
,返回包装的 readers。
Examples
use std::io;
use std::io::prelude::*;
use std::fs::File;
fn main() -> io::Result<()> {
let mut foo_file = File::open("foo.txt")?;
let mut bar_file = File::open("bar.txt")?;
let chain = foo_file.chain(bar_file);
let (foo_file, bar_file) = chain.into_inner();
Ok(())
}
Run1.20.0 · sourcepub fn get_ref(&self) -> (&T, &U)
pub fn get_ref(&self) -> (&T, &U)
获取此 Chain
中的底层 readers 的引用。
Examples
use std::io;
use std::io::prelude::*;
use std::fs::File;
fn main() -> io::Result<()> {
let mut foo_file = File::open("foo.txt")?;
let mut bar_file = File::open("bar.txt")?;
let chain = foo_file.chain(bar_file);
let (foo_file, bar_file) = chain.get_ref();
Ok(())
}
Run1.20.0 · sourcepub fn get_mut(&mut self) -> (&mut T, &mut U)
pub fn get_mut(&mut self) -> (&mut T, &mut U)
获取此 Chain
中的底层 readers 的可变引用。
应注意避免修改底层 readers 的内部 I/O 状态,因为这样做可能会破坏该 Chain
的内部状态。
Examples
use std::io;
use std::io::prelude::*;
use std::fs::File;
fn main() -> io::Result<()> {
let mut foo_file = File::open("foo.txt")?;
let mut bar_file = File::open("bar.txt")?;
let mut chain = foo_file.chain(bar_file);
let (foo_file, bar_file) = chain.get_mut();
Ok(())
}
RunTrait Implementations§
1.9.0 · source§impl<T: BufRead, U: BufRead> BufRead for Chain<T, U>
impl<T: BufRead, U: BufRead> BufRead for Chain<T, U>
source§fn fill_buf(&mut self) -> Result<&[u8]>
fn fill_buf(&mut self) -> Result<&[u8]>
返回内部缓冲区的内容,如果内部缓冲区为空,则使用内部 reader 中的更多数据填充内部缓冲区。 Read more
source§fn has_data_left(&mut self) -> Result<bool>
fn has_data_left(&mut self) -> Result<bool>
🔬This is a nightly-only experimental API. (
buf_read_has_data_left
#86423)检查底层
Read
是否有任何数据可供读取。 Read moresource§impl<T: Read, U: Read> Read for Chain<T, U>
impl<T: Read, U: Read> Read for Chain<T, U>
source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize>
与
read
相似,不同之处在于它读入缓冲区的一部分。 Read moresource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
🔬This is a nightly-only experimental API. (
can_vector
#69941)source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize>
读取所有字节,直到此源中的 EOF 为止,然后将它们放入
buf
。 Read moresource§fn read_to_string(&mut self, buf: &mut String) -> Result<usize>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize>
读取这个源中的所有字节,直到 EOF 为止,然后将它们追加到
buf
。 Read moresource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<()>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<()>
🔬This is a nightly-only experimental API. (
read_buf
#78485)从此源中提取一些字节到指定的缓冲区中。 Read more
source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<()>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<()>
🔬This is a nightly-only experimental API. (
read_buf
#78485)读取填充
cursor
所需的确切字节数。 Read moresource§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere Self: Sized,
为这个
Read
实例创建一个 “by reference” 适配器。 Read more