2015-03-17 20:33:26 +00:00
|
|
|
use std::io::{self, Read};
|
2014-09-11 22:54:44 +00:00
|
|
|
use std::vec;
|
|
|
|
|
|
|
|
pub struct Container<'a> {
|
2019-05-28 18:46:13 +00:00
|
|
|
reader: &'a mut dyn Read
|
2014-09-11 22:54:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Container<'a> {
|
2019-05-28 18:46:13 +00:00
|
|
|
pub fn wrap<'s>(reader: &'s mut dyn io::Read) -> Container<'s> {
|
2014-09-11 22:54:44 +00:00
|
|
|
Container { reader: reader }
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn read_to(&mut self, vec: &mut [u8]) {
|
|
|
|
self.reader.read(vec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn for_stdin<'a>() -> Container<'a> {
|
2015-03-17 20:33:26 +00:00
|
|
|
let mut r = io::stdin();
|
2019-05-28 18:46:13 +00:00
|
|
|
Container::wrap(&mut r as &mut dyn io::Read)
|
2024-02-01 22:45:00 +00:00
|
|
|
//~^ ERROR cannot return value referencing local variable
|
2014-09-11 22:54:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let mut c = for_stdin();
|
2015-01-02 07:53:35 +00:00
|
|
|
let mut v = Vec::new();
|
2016-11-09 23:25:45 +00:00
|
|
|
c.read_to(v); //~ ERROR E0308
|
2014-09-11 22:54:44 +00:00
|
|
|
}
|