Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::sync::mpsc::Sender;
- struct Message1 {
- i: i32,
- }
- struct Message2 {
- j: u64,
- }
- trait Serialize {}
- impl Serialize for Message1 {}
- impl Serialize for Message2 {}
- type BufType = [u8; 2048];
- trait Sync {
- fn send(b: &BufType);
- }
- struct Serializer<'a, 'b> {
- buf: BufType,
- next_buf: Option<BufType>,
- ready: Sender<&'a BufType>,
- sync: &'b Sync,
- }
- impl<'a, 'b, 'c> Serializer<'a, 'b> {
- /// If next_buf isn't empty - move data to buf
- /// Serialize to buf
- /// If message is too long serialize the rest in next_buf
- fn serialize<'t>(&mut self, val: &'t Serialize) {
- unimplemented!()
- }
- fn serialize_batch(&mut self) {
- while let Ok(val) = self.new_msgs.try_recv() {
- self.serialize(val);
- if self.next_buf.is_some() {
- self.sync.send(&self.buf);
- }
- }
- }
- }
- fn main() {
- println!("Hello, world!");
- }
Add Comment
Please, Sign In to add comment