1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use std::fmt::Debug;
use message::Delivery;

#[derive(Debug)]
pub struct Consumer {
      tag:             String,
      no_local:        bool,
      no_ack:          bool,
      exclusive:       bool,
      nowait:          bool,
      subscriber:      Box<ConsumerSubscriber>,
  pub current_message: Option<Delivery>,
}

impl Consumer {
  pub fn new(tag: String, no_local: bool, no_ack: bool, exclusive: bool, nowait: bool, subscriber: Box<ConsumerSubscriber>) -> Consumer {
    Consumer {
      tag,
      no_local,
      no_ack,
      exclusive,
      nowait,
      subscriber,
      current_message: None,
    }
  }

  pub fn new_delivery_complete(&mut self) {
    if let Some(delivery) = self.current_message.take() {
      self.subscriber.new_delivery(delivery);
    }
  }
}

pub trait ConsumerSubscriber: Debug+Send+Sync {
  fn new_delivery(&mut self, delivery: Delivery);
}