Advertisement
Guest User

Untitled

a guest
Jul 5th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 1.47 KB | None | 0 0
  1.     pub fn update(&mut self, event: &mut ClientEvent) {
  2.         let mut buffer = [0u8;1024];
  3.         let mut first = true;
  4.         loop {
  5.             match self.stream.read(&mut buffer) {
  6.                 Ok(0) if first |
  7.                 Err(ref e) if e.kind() == ::std::io::ErrorKind::WouldBlock && !first => {
  8.                     println!("First read resulted in no bytes");
  9.                     break;
  10.                 },
  11.                 Ok(length) => {
  12.                     first = false;
  13.                     println!("Read {} bytes: {:?}", length, ::std::str::from_utf8(&buffer[0..length]));
  14.                     self.read_buffer.extend_from_slice(&buffer[0..length]);
  15.                 },
  16.                                 Err(e) => {
  17.                     println!("Could not read: {} ({:?})", e, e.kind());
  18.                     break;
  19.                 }
  20.             };
  21.         }
  22.     }
  23.  
  24. /*
  25. error: expected expression, found keyword `ref`
  26.   --> src/client.rs:41:21
  27.    |
  28. 41 |                 Err(ref e) if e.kind() == ::std::io::ErrorKind::WouldBlock && !first => {
  29.    |                     ^^^
  30.  
  31. error: expected one of `)`, `.`, `<`, `=>`, `?`, `break`, `continue`, `false`, `for`, `if`, `loop`, `match`, `move`, `return`, `true`, `unsafe`, `while`, or an operator, found `ref`
  32.   --> src/client.rs:41:21
  33.    |
  34. 41 |                 Err(ref e) if e.kind() == ::std::io::ErrorKind::WouldBlock && !first => {
  35.    |                     ^^^ expected one of 18 possible tokens here
  36.  
  37. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement