Skip to main content

zulip_api/api/
key.rs

1use zeroize::Zeroize;
2
3/// Represents a Zulip API key used to authenticate to the service.
4#[derive(Clone, Debug, Eq, PartialEq, Zeroize)]
5pub struct ApiKey(String);
6
7impl ApiKey {
8    /// Creates a new [ApiKey].
9    pub const fn new() -> Self {
10        Self(String::new())
11    }
12
13    /// Gets the string representation of the [ApiKey].
14    pub fn as_str(&self) -> &str {
15        self.0.as_str()
16    }
17}
18
19impl Default for ApiKey {
20    fn default() -> Self {
21        Self::new()
22    }
23}
24
25impl From<&str> for ApiKey {
26    fn from(val: &str) -> Self {
27        Self(val.into())
28    }
29}
30
31impl From<String> for ApiKey {
32    fn from(val: String) -> Self {
33        Self(val)
34    }
35}