Guest User

Untitled

a guest
Dec 14th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. use std::sync::mpsc::Sender;
  2.  
  3. struct Message1 {
  4. i: i32,
  5. }
  6.  
  7. struct Message2 {
  8. j: u64,
  9. }
  10.  
  11. trait Serialize {}
  12.  
  13. impl Serialize for Message1 {}
  14. impl Serialize for Message2 {}
  15.  
  16. type BufType = [u8; 2048];
  17.  
  18. trait Sync {
  19. fn send(b: &BufType);
  20. }
  21.  
  22. struct Serializer<'a, 'b> {
  23. buf: BufType,
  24. next_buf: Option<BufType>,
  25. ready: Sender<&'a BufType>,
  26. sync: &'b Sync,
  27. }
  28.  
  29. impl<'a, 'b, 'c> Serializer<'a, 'b> {
  30. /// If next_buf isn't empty - move data to buf
  31. /// Serialize to buf
  32. /// If message is too long serialize the rest in next_buf
  33. fn serialize<'t>(&mut self, val: &'t Serialize) {
  34. unimplemented!()
  35. }
  36.  
  37. fn serialize_batch(&mut self) {
  38. while let Ok(val) = self.new_msgs.try_recv() {
  39. self.serialize(val);
  40. if self.next_buf.is_some() {
  41. self.sync.send(&self.buf);
  42. }
  43. }
  44. }
  45. }
  46.  
  47. fn main() {
  48. println!("Hello, world!");
  49. }
Add Comment
Please, Sign In to add comment