1pub mod list;
4
5use crate::{Decode, DecodeError, Encode, Error, ErrorKind};
6
7pub use crate::types::{
8 ApiKeyId, ChannelGroupId, ChannelId, ClientDatabaseId, ClientId, ServerGroupId, ServerId,
9};
10
11pub use list::List;
12
13#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
14pub enum ApiKeyScope {
15 Manage,
16 Write,
17 Read,
18}
19
20impl ApiKeyScope {
21 const MANAGE: &str = "manage";
22 const WRITE: &str = "write";
23 const READ: &str = "read";
24}
25
26impl Default for ApiKeyScope {
27 fn default() -> Self {
28 Self::Manage
29 }
30}
31
32impl Encode for ApiKeyScope {
33 fn encode(&self, buf: &mut String) {
34 match self {
35 Self::Manage => *buf += Self::MANAGE,
36 Self::Write => *buf += Self::WRITE,
37 Self::Read => *buf += Self::READ,
38 }
39 }
40}
41
42impl Decode for ApiKeyScope {
43 type Error = Error;
44
45 fn decode(buf: &[u8]) -> Result<Self, Self::Error> {
46 let s = String::decode(buf)?;
47
48 match s.as_str() {
49 Self::MANAGE => Ok(Self::Manage),
50 Self::WRITE => Ok(Self::Write),
51 Self::READ => Ok(Self::Read),
52 _ => Err(Error(ErrorKind::Decode(DecodeError::InvalidApiKeyScope(s)))),
53 }
54 }
55}