actix_amqp/server/
link.rs

1use std::fmt;
2
3use actix_router::Path;
4use amqp_codec::protocol::Attach;
5use bytestring::ByteString;
6
7use crate::cell::Cell;
8use crate::rcvlink::ReceiverLink;
9use crate::server::State;
10use crate::session::Session;
11use crate::{Configuration, Handle};
12
13pub struct Link<S> {
14    pub(crate) state: State<S>,
15    pub(crate) link: ReceiverLink,
16    pub(crate) path: Path<ByteString>,
17}
18
19impl<S> Link<S> {
20    pub(crate) fn new(link: ReceiverLink, state: State<S>) -> Self {
21        Link {
22            state,
23            link,
24            path: Path::new(ByteString::from_static("")),
25        }
26    }
27
28    pub fn path(&self) -> &Path<ByteString> {
29        &self.path
30    }
31
32    pub fn path_mut(&mut self) -> &mut Path<ByteString> {
33        &mut self.path
34    }
35
36    pub fn frame(&self) -> &Attach {
37        self.link.frame()
38    }
39
40    pub fn state(&self) -> &S {
41        self.state.get_ref()
42    }
43
44    pub fn state_mut(&mut self) -> &mut S {
45        self.state.get_mut()
46    }
47
48    pub fn handle(&self) -> Handle {
49        self.link.handle()
50    }
51
52    pub fn session(&self) -> &Session {
53        self.link.session()
54    }
55
56    pub fn session_mut(&mut self) -> &mut Session {
57        self.link.session_mut()
58    }
59
60    pub fn link_credit(mut self, credit: u32) {
61        self.link.set_link_credit(credit);
62    }
63
64    #[inline]
65    /// Get remote connection configuration
66    pub fn remote_config(&self) -> &Configuration {
67        &self.link.remote_config()
68    }
69}
70
71impl<S> Clone for Link<S> {
72    fn clone(&self) -> Self {
73        Self {
74            state: self.state.clone(),
75            link: self.link.clone(),
76            path: self.path.clone(),
77        }
78    }
79}
80
81impl<S> fmt::Debug for Link<S> {
82    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
83        fmt.debug_struct("Link<S>")
84            .field("frame", self.link.frame())
85            .finish()
86    }
87}