speedrun_api/api/
regions.rs1use std::{borrow::Cow, fmt::Display};
5
6use serde::{Deserialize, Serialize};
7
8use super::{endpoint::Endpoint, error::BodyError, query_params::QueryParams, Direction, Pageable};
9
10#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq, Hash)]
12pub struct RegionId<'a>(Cow<'a, str>);
13
14impl<'a> RegionId<'a> {
15 pub fn new<T>(id: T) -> Self
17 where
18 T: Into<Cow<'a, str>>,
19 {
20 Self(id.into())
21 }
22}
23
24impl<'a, T> From<T> for RegionId<'a>
25where
26 T: Into<Cow<'a, str>>,
27{
28 fn from(value: T) -> Self {
29 Self::new(value)
30 }
31}
32
33impl Display for RegionId<'_> {
34 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
35 write!(f, "{}", &self.0)
36 }
37}
38
39#[derive(Default, Debug, Builder, Serialize, Clone)]
41#[builder(default, setter(into, strip_option))]
42#[serde(rename_all = "kebab-case")]
43pub struct Regions {
44 #[doc = r"Sort direction. Regions are currently only sorted alphanumerically by the region name."]
45 direction: Option<Direction>,
46}
47
48#[derive(Debug, Builder, Clone)]
50#[builder(setter(into, strip_option))]
51pub struct Region<'a> {
52 #[doc = r"`ID` of the region."]
53 id: RegionId<'a>,
54}
55
56impl Regions {
57 pub fn builder() -> RegionsBuilder {
59 RegionsBuilder::default()
60 }
61}
62
63impl Region<'_> {
64 pub fn builder<'a>() -> RegionBuilder<'a> {
66 RegionBuilder::default()
67 }
68}
69
70impl Endpoint for Regions {
71 fn endpoint(&self) -> std::borrow::Cow<'static, str> {
72 "/regions".into()
73 }
74
75 fn query_parameters(&self) -> Result<QueryParams<'_>, BodyError> {
76 QueryParams::with(self)
77 }
78}
79
80impl Endpoint for Region<'_> {
81 fn endpoint(&self) -> Cow<'static, str> {
82 format!("/regions/{}", self.id).into()
83 }
84}
85
86impl Pageable for Regions {}