Skip to main content

io_providers/stream/
std_provider.rs

1use std::io;
2use stream;
3
4/// Provides access to the standard streams (stdin, stdout and stderr).
5pub struct Std {
6    stdin: io::Stdin,
7    stdout: io::Stdout,
8    stderr: io::Stderr,
9}
10
11impl Std {
12    /// Constructs a new standard stream provider.
13    pub fn new() -> Std {
14        Std {
15            stdin: io::stdin(),
16            stdout: io::stdout(),
17            stderr: io::stderr(),
18        }
19    }
20}
21
22impl stream::Provider for Std {
23    fn input(&mut self) -> &mut io::Read {
24        &mut self.stdin
25    }
26
27    fn output(&mut self) -> &mut io::Write {
28        &mut self.stdout
29    }
30
31    fn error(&mut self) -> &mut io::Write {
32        &mut self.stderr
33    }
34}