zino_channel/
subscription.rs

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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use serde::{Deserialize, Serialize};

/// Subscription.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[serde(default)]
pub struct Subscription {
    /// Session ID.
    session_id: Option<String>,
    /// Source.
    source: Option<String>,
    /// Topic.
    topic: Option<String>,
}

impl Subscription {
    /// Creates a new instance.
    #[inline]
    pub fn new(source: Option<String>, topic: Option<String>) -> Self {
        Self {
            session_id: None,
            source,
            topic,
        }
    }

    /// Sets the session ID.
    #[inline]
    pub fn set_session_id(&mut self, session_id: Option<String>) {
        self.session_id = session_id;
    }

    /// Sets the source.
    #[inline]
    pub fn set_source(&mut self, source: Option<String>) {
        self.source = source;
    }

    /// Sets the topic.
    #[inline]
    pub fn set_topic(&mut self, topic: Option<String>) {
        self.topic = topic;
    }

    /// Returns the session ID.
    #[inline]
    pub fn session_id(&self) -> Option<&str> {
        self.session_id.as_deref()
    }

    /// Returns the source.
    #[inline]
    pub fn source(&self) -> Option<&str> {
        self.source.as_deref()
    }

    /// Returns the topic.
    #[inline]
    pub fn topic(&self) -> Option<&str> {
        self.topic.as_deref()
    }
}