zlink_core/call/
mod.rs

1// We manually implement `Serialize` and `Deserialize` for `Call` because we need to flatten the
2// `method` field and `serde` requires `alloc` for both serialization and deserialization when
3// using the `flatten` attribute.
4mod de;
5mod ser;
6
7#[cfg(test)]
8mod tests;
9
10/// A method call.
11#[derive(Debug, Clone)]
12pub struct Call<M> {
13    pub(super) method: M,
14    pub(super) oneway: bool,
15    pub(super) more: bool,
16    pub(super) upgrade: bool,
17}
18
19impl<M> Call<M> {
20    /// Create a new method call.
21    pub fn new(method: M) -> Self {
22        Self {
23            method,
24            oneway: false,
25            more: false,
26            upgrade: false,
27        }
28    }
29
30    /// Set the oneway flag.
31    pub fn set_oneway(mut self, oneway: bool) -> Self {
32        self.oneway = oneway;
33        self
34    }
35
36    /// Set the more flag.
37    pub fn set_more(mut self, more: bool) -> Self {
38        self.more = more;
39        self
40    }
41
42    /// Set the upgrade flag.
43    pub fn set_upgrade(mut self, upgrade: bool) -> Self {
44        self.upgrade = upgrade;
45        self
46    }
47
48    /// The method call name and parameters.
49    pub fn method(&self) -> &M {
50        &self.method
51    }
52
53    /// If the method call doesn't want a reply.
54    pub fn oneway(&self) -> bool {
55        self.oneway
56    }
57
58    /// If the method call is requesting more replies.
59    pub fn more(&self) -> bool {
60        self.more
61    }
62
63    /// If the method call is requesting an upgrade to a different protocol.
64    pub fn upgrade(&self) -> bool {
65        self.upgrade
66    }
67}
68
69impl<M> From<M> for Call<M> {
70    fn from(method: M) -> Self {
71        Self::new(method)
72    }
73}