Redirectable

Trait Redirectable 

Source
pub trait Redirectable<T: ?Sized> {
    // Required method
    fn redirect(&mut self, destination: &T) -> Result<()>;
}
Expand description

A trait to represent entities that can have their I/O redirected to a specified target.

§Type Parameters

  • T: The type of the destination. It is a dynamically sized type (?Sized) so that it can be used with types that do not have a statically known size.

§Notes

Be cautious of potential side effects or resource management issues when implementing this trait, especially in cases where redirection involves I/O operations or state transitions.

Required Methods§

Source

fn redirect(&mut self, destination: &T) -> Result<()>

Redirects I/O to a specified destination.

§Parameters
  • destination: A reference to the target destination.
§Returns
  • io::Result<()>: Ok if successful, Err otherwise.
§Examples
use io_redirect::Redirectable;

let mut source = std::io::stdout();
let destination = std::fs::File::create("dst.txt").unwrap();
match source.redirect(&destination) {
    Ok(_) => println!("Redirection successful!"),
    Err(_) => eprintln!("Failed to redirect!"),
}
§Notes

The behavior of this function depends on the implementation.

Implementors§