acick_util/model/
service.rs1use std::fmt;
2use std::hash::Hash;
3
4use getset::CopyGetters;
5use serde::{Deserialize, Serialize};
6
7#[derive(Serialize, Deserialize, CopyGetters, Debug, Clone, PartialEq, Eq, Hash)]
8pub struct Service {
9 #[get_copy = "pub"]
10 id: ServiceKind,
11}
12
13impl Service {
14 pub fn new(id: ServiceKind) -> Self {
15 Self { id }
16 }
17}
18
19impl Default for Service {
20 fn default() -> Self {
21 Self::new(ServiceKind::default())
22 }
23}
24
25#[derive(
26 Serialize,
27 Deserialize,
28 EnumString,
29 EnumVariantNames,
30 IntoStaticStr,
31 Debug,
32 Copy,
33 Clone,
34 PartialEq,
35 Eq,
36 PartialOrd,
37 Ord,
38 Hash,
39)]
40#[serde(rename_all = "kebab-case")]
41#[strum(serialize_all = "kebab-case")]
42pub enum ServiceKind {
43 Atcoder,
44}
45
46impl ServiceKind {
47 pub fn to_user_pass_env_names(self) -> (&'static str, &'static str) {
48 match self {
49 Self::Atcoder => ("ACICK_ATCODER_USERNAME", "ACICK_ATCODER_PASSWORD"),
50 }
51 }
52}
53
54impl Default for ServiceKind {
55 fn default() -> Self {
56 Self::Atcoder
57 }
58}
59
60impl fmt::Display for ServiceKind {
61 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
62 f.write_str(self.into())
63 }
64}
65
66#[cfg(test)]
67mod tests {
68 use super::*;
69
70 #[test]
71 fn test_service_kind_default_display() {
72 assert_eq!(ServiceKind::default().to_string(), "atcoder");
73 }
74}