Skip to main content

Chain

Struct Chain 

Source
#[non_exhaustive]
pub struct Chain<T, U> { /* private fields */ }
๐Ÿ”ฌThis is a nightly-only experimental API. (core_io #154046)
Expand description

Adapter to chain together two readers.

This struct is generally created by calling chain on a reader. Please see the documentation of chain for more details.

Implementationsยง

Sourceยง

impl<T, U> Chain<T, U>

1.20.0 ยท Source

pub fn into_inner(self) -> (T, U)

Consumes the Chain, returning the wrapped 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(())
}
1.20.0 ยท Source

pub fn get_ref(&self) -> (&T, &U)

Gets references to the underlying readers in this Chain.

Care should be taken to avoid modifying the internal I/O state of the underlying readers as doing so may corrupt the internal state of this 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 chain = foo_file.chain(bar_file);
    let (foo_file, bar_file) = chain.get_ref();
    Ok(())
}
1.20.0 ยท Source

pub fn get_mut(&mut self) -> (&mut T, &mut U)

Gets mutable references to the underlying readers in this Chain.

Care should be taken to avoid modifying the internal I/O state of the underlying readers as doing so may corrupt the internal state of this 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(())
}

Trait Implementationsยง

1.0.0 ยท Sourceยง

impl<T: Debug, U: Debug> Debug for Chain<T, U>

Sourceยง

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementationsยง

ยง

impl<T, U> Freeze for Chain<T, U>
where T: Freeze, U: Freeze,

ยง

impl<T, U> RefUnwindSafe for Chain<T, U>

ยง

impl<T, U> Send for Chain<T, U>
where T: Send, U: Send,

ยง

impl<T, U> Sync for Chain<T, U>
where T: Sync, U: Sync,

ยง

impl<T, U> Unpin for Chain<T, U>
where T: Unpin, U: Unpin,

ยง

impl<T, U> UnsafeUnpin for Chain<T, U>
where T: UnsafeUnpin, U: UnsafeUnpin,

ยง

impl<T, U> UnwindSafe for Chain<T, U>
where T: UnwindSafe, U: UnwindSafe,

Blanket Implementationsยง

Sourceยง

impl<T> Any for T
where T: 'static + ?Sized,

Sourceยง

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Sourceยง

impl<T> Borrow<T> for T
where T: ?Sized,

Sourceยง

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Sourceยง

impl<T> BorrowMut<T> for T
where T: ?Sized,

Sourceยง

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Sourceยง

impl<T> From<T> for T

Sourceยง

fn from(t: T) -> T

Returns the argument unchanged.

Sourceยง

impl<T, U> Into<U> for T
where U: From<T>,

Sourceยง

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Sourceยง

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Sourceยง

type Error = Infallible

The type returned in the event of a conversion error.
Sourceยง

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Sourceยง

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Sourceยง

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Sourceยง

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.