firebae_cm/message/
receiver.rs

1/// Represents a receiver of your message.
2/// Can be a Token (for a single device),
3/// a Topic (for all devices that have subscribed to that topic),
4/// or a Condition (for all devices that meet the condition).
5/// See the fields in [the documentation](https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#resource:-message).
6#[derive(serde::Serialize, Debug)]
7#[serde(rename_all = "lowercase")]
8pub enum Receiver {
9    Token(String),
10    Topic(String),
11    Condition(String),
12}
13
14impl Receiver {
15    /// Create a Token variant with anything that implements `Into<String>` (such as `&str`).
16    /// ```rust
17    /// let token = Receiver::token("abcd");
18    /// ```
19    pub fn token(token: impl Into<String>) -> Self {
20        Self::Token(token.into())
21    }
22
23    /// Create a Topic variant with anything that implements `Into<String>` (such as `&str`).
24    /// ```rust
25    /// let topic = Receiver::topic("abcd");
26    /// ```
27    pub fn topic(topic: impl Into<String>) -> Self {
28        Self::Topic(topic.into())
29    }
30
31    /// Create a Condition variant with anything that implements `Into<String>` (such as `&str`).
32    /// ```rust
33    /// let condition = Receiver::condition("abcd");
34    /// ```
35    pub fn condition(condition: impl Into<String>) -> Self {
36        Self::Condition(condition.into())
37    }
38}