Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::io::{Read, Write};
- use std::io::Error;
- use std::io::stdin;
- /*
- enum Action {
- ReadByte(u8),
- ReadString(Vec<u8>),
- Pause(u8),
- Failure(Error)
- }
- struct MockStdIo {
- actions: Vec<Action>
- }
- impl MockStdIo {
- fn build_from_actions(input:&[Action]) -> Self {
- unimplemented!();
- }
- }
- impl Read for MockStdIo {
- fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error> {
- match self.actions.pop() {
- Some(Action::Read(output)) => {
- let output = buf.write(&output);
- unimplemented!();
- }
- None => {
- Ok(0)
- }
- _ => {
- unimplemented!();
- }
- }
- }
- }*/
- fn main() {
- let mut test_input = "This is a test input".as_bytes();
- generic(&mut test_input);
- generic(&mut stdin());
- }
- pub fn generic<R: Read>(r: &mut R){
- let mut x = String::new();
- println!("Reading out {:?}", r.read_to_string(&mut x));
- println!("With string {:?}", x);
- }
- pub fn by_trait(r: &mut Read){
- let mut x = String::new();
- println!("Reading out {:?}", r.read_to_string(&mut x));
- println!("With string {:?}", x);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement