lapin_async/
confirmation.rs1#[deprecated(note = "use lapin instead")]
2pub use crate::wait::NotifyReady;
3
4use std::fmt;
5
6use crate:: {
7 error::Error,
8 wait::Wait,
9};
10
11#[deprecated(note = "use lapin instead")]
12pub struct Confirmation<T, I=()> {
13 kind: ConfirmationKind<T, I>,
14}
15
16impl<T, I> Confirmation<T, I> {
17 pub(crate) fn new(wait: Wait<T>) -> Self {
18 Self { kind: ConfirmationKind::Wait(wait) }
19 }
20
21 pub(crate) fn new_error(error: Error) -> Self {
22 let (wait, wait_handle) = Wait::new();
23 wait_handle.error(error);
24 Self::new(wait)
25 }
26
27 #[deprecated(note = "use lapin instead")]
28 pub fn as_error(self) -> Result<(), Error> {
29 self.try_wait().transpose().map(|_| ())
30 }
31
32 #[deprecated(note = "use lapin instead")]
33 pub fn subscribe(&self, task: Box<dyn NotifyReady + Send>) {
34 match &self.kind {
35 ConfirmationKind::Wait(wait) => wait.subscribe(task),
36 ConfirmationKind::Map(wait, _) => wait.subscribe(task),
37 }
38 }
39
40 #[deprecated(note = "use lapin instead")]
41 pub fn has_subscriber(&self) -> bool {
42 match &self.kind {
43 ConfirmationKind::Wait(wait) => wait.has_subscriber(),
44 ConfirmationKind::Map(wait, _) => wait.has_subscriber(),
45 }
46 }
47
48 #[deprecated(note = "use lapin instead")]
49 pub fn try_wait(&self) -> Option<Result<T, Error>> {
50 match &self.kind {
51 ConfirmationKind::Wait(wait) => wait.try_wait(),
52 ConfirmationKind::Map(wait, f) => wait.try_wait().map(|res| res.map(f)),
53 }
54 }
55
56 #[deprecated(note = "use lapin instead")]
57 pub fn wait(self) -> Result<T, Error> {
58 match self.kind {
59 ConfirmationKind::Wait(wait) => wait.wait(),
60 ConfirmationKind::Map(wait, f) => wait.wait().map(f),
61 }
62 }
63}
64
65impl<T> Confirmation<T> {
66 pub(crate) fn map<M>(self, f: Box<dyn Fn(T) -> M + Send + 'static>) -> Confirmation<M, T> {
67 Confirmation { kind: ConfirmationKind::Map(Box::new(self), f) }
68 }
69}
70
71enum ConfirmationKind<T, I> {
72 Wait(Wait<T>),
73 Map(Box<Confirmation<I>>, Box<dyn Fn(I) -> T + Send + 'static>)
74}
75
76impl<T> From<Result<Wait<T>, Error>> for Confirmation<T> {
77 fn from(res: Result<Wait<T>, Error>) -> Self {
78 match res {
79 Ok(wait) => Confirmation::new(wait),
80 Err(err) => Confirmation::new_error(err),
81 }
82 }
83}
84
85impl<T> fmt::Debug for Confirmation<T> {
86 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
87 write!(f, "Confirmation")
88 }
89}