Skip to content

Commit

Permalink
Can now create a ShellIO instance with single Read+Write object
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Henri Symoneaux committed Jun 16, 2016
1 parent 31ae1b3 commit f0e7db6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn main() {
for sock in serv.incoming() {
let sock = sock.unwrap();
let mut shell = shell.clone();
let io = ShellIO::new(sock.try_clone().unwrap(), sock.try_clone().unwrap());
let io = ShellIO::new_io(sock);
shell.set_io(io);
thread::spawn(move || shell.run_loop());
}
Expand Down
13 changes: 12 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,24 @@ pub struct ShellIO {
impl ShellIO {
/// Create a new Shell I/O wrapping provided Input and Output
pub fn new<I, O>(input: I, output: O) -> ShellIO
where I: io::Read+Send+'static, O: io::Write+Send+'static
where I: Read + Send + 'static, O: Write + Send + 'static
{
return ShellIO {
input: Arc::new(Mutex::new(input)),
output: Arc::new(Mutex::new(output))
};
}

/// Create a new Shell I/O wrapping provided Read/Write io
pub fn new_io<T>(io: T) -> ShellIO
where T: Read + Write + Send + 'static
{
let io = Arc::new(Mutex::new(io));
return ShellIO {
input: io.clone(),
output: io
};
}
}

impl Read for ShellIO {
Expand Down

0 comments on commit f0e7db6

Please sign in to comment.