lapin_async/
channel_status.rs

1use parking_lot::RwLock;
2
3use std::sync::Arc;
4
5use crate::types::ShortString;
6
7#[derive(Clone, Debug, Default)]
8#[deprecated(note = "use lapin instead")]
9pub struct ChannelStatus {
10  inner: Arc<RwLock<Inner>>,
11}
12
13impl ChannelStatus {
14  #[deprecated(note = "use lapin instead")]
15  pub fn is_initializing(&self) -> bool {
16    self.inner.read().state == ChannelState::Initial
17  }
18
19  #[deprecated(note = "use lapin instead")]
20  pub fn is_closing(&self) -> bool {
21    self.inner.read().state == ChannelState::Closing
22  }
23
24  #[deprecated(note = "use lapin instead")]
25  pub fn is_connected(&self) -> bool {
26    !&[ChannelState::Initial, ChannelState::Closing, ChannelState::Closed, ChannelState::Error].contains(&self.inner.read().state)
27  }
28
29  #[deprecated(note = "use lapin instead")]
30  pub fn confirm(&self) -> bool {
31    self.inner.read().confirm
32  }
33
34  pub(crate) fn set_confirm(&self) {
35    self.inner.write().confirm = true
36  }
37
38  #[deprecated(note = "use lapin instead")]
39  pub fn state(&self) -> ChannelState {
40    self.inner.read().state.clone()
41  }
42
43  pub(crate) fn set_state(&self, state: ChannelState) {
44    self.inner.write().state = state
45  }
46
47  pub(crate) fn set_send_flow(&self, flow: bool) {
48    self.inner.write().send_flow = flow;
49  }
50
51  pub(crate) fn flow(&self) -> bool {
52    self.inner.read().send_flow
53  }
54}
55
56#[derive(Clone, Debug, PartialEq, Eq)]
57#[deprecated(note = "use lapin instead")]
58pub enum ChannelState {
59    Initial,
60    Connected,
61    Closing,
62    Closed,
63    Error,
64    SendingContent(usize),
65    WillReceiveContent(Option<ShortString>, Option<ShortString>),
66    ReceivingContent(Option<ShortString>, Option<ShortString>, usize),
67}
68
69impl Default for ChannelState {
70  fn default() -> Self {
71    ChannelState::Initial
72  }
73}
74
75#[derive(Debug)]
76struct Inner {
77  confirm:   bool,
78  send_flow: bool,
79  state:     ChannelState,
80}
81
82impl Default for Inner {
83  fn default() -> Self {
84    Self {
85      confirm:   false,
86      send_flow: true,
87      state:     ChannelState::default(),
88    }
89  }
90}