1use std::fmt::Display;
2
3use serde::{Deserialize, Serialize};
4
5pub mod authenticated;
6pub mod game_mechanics;
7pub mod guild;
8pub mod home_instance;
9pub mod items;
10pub mod maps;
11pub mod misc;
12pub mod pvp;
13pub mod tradingpost;
14pub mod wvw;
15
16#[derive(Hash, Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
17pub enum Language {
18 En,
19 Fr,
20 De,
21 Es,
22 Zh,
23}
24
25impl Display for Language {
26 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
27 std::fmt::Debug::fmt(self, f)
28 }
29}
30
31impl Language {
32 pub fn as_str(&self) -> &'static str {
33 match self {
34 Language::En => "en",
35 Language::Fr => "fr",
36 Language::De => "de",
37 Language::Es => "es",
38 Language::Zh => "zh",
39 }
40 }
41}
42
43impl From<&str> for Language {
44 fn from(v: &str) -> Self {
45 match v {
46 "en" => Language::En,
47 "fr" => Language::Fr,
48 "de" => Language::De,
49 "es" => Language::Es,
50 "zh" => Language::Zh,
51 _ => Language::En,
52 }
53 }
54}
55
56pub type TimeStamp = String;
57
58#[derive(Hash, Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
59pub struct ErrorResponse {
60 pub text: String,
61}
62
63pub trait Endpoint: Sized {
64 const AUTHENTICATED: bool;
66
67 const LOCALE: bool;
69
70 const URL: &'static str;
77
78 const VERSION: &'static str;
80}
81
82pub trait EndpointWithId: Endpoint {
83 type IdType: Display;
84
85 fn format_id(id: &Self::IdType) -> String {
86 urlencoding::encode(&id.to_string()).into_owned()
87 }
88
89 fn format_url(id: &str) -> String {
90 format!("{}/{}", Self::URL, id)
91 }
92}
93
94pub trait FixedEndpoint: Endpoint {}
95
96pub trait BulkEndpoint: EndpointWithId {
97 const ALL: bool;
99
100 fn id(&self) -> &Self::IdType;
101}
102
103pub trait PagedEndpoint: Endpoint {}
104
105impl<T: BulkEndpoint> PagedEndpoint for T {}