Skip to content

Instantly share code, notes, and snippets.

@Troxid
Last active September 10, 2016 08:21
Show Gist options
  • Select an option

  • Save Troxid/6fb396b2b126fc806076f00941f4ece9 to your computer and use it in GitHub Desktop.

Select an option

Save Troxid/6fb396b2b126fc806076f00941f4ece9 to your computer and use it in GitHub Desktop.
struct Server{
out_buffer: Vec<String>,
in_buffer: Vec<String>,
...
}
impl Server {
fn send(&mut self, msg: String){
self.in_buffer.push(msg);
}
fn recv(&mut self) -> Option<String>{
self.out_buffer.pop();
}
fn run(&mut self){
thread::spawn(move ||{
loop{
// mutate out_buffer
// mutate in_buffer
// mutate other fields
}
});
}
}
fn main(){
let s = Server::new();
s.run() //non blocking
s.send("hello".into());
let msg = s.recv().unwrup();
println!("{:?}", msg);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment