speedrun_api/api/
developers.rs1use std::{borrow::Cow, fmt::Display};
6
7use serde::{Deserialize, Serialize};
8
9use super::{endpoint::Endpoint, error::BodyError, query_params::QueryParams, Direction, Pageable};
10
11#[derive(Debug, Serialize, Clone, Copy)]
13#[serde(rename_all = "kebab-case")]
14pub enum DevelopersSorting {
15 Name,
17}
18
19#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq, Hash)]
21pub struct DeveloperId<'a>(Cow<'a, str>);
22
23impl<'a> DeveloperId<'a> {
24 pub fn new<T>(id: T) -> Self
26 where
27 T: Into<Cow<'a, str>>,
28 {
29 Self(id.into())
30 }
31}
32
33impl<'a, T> From<T> for DeveloperId<'a>
34where
35 T: Into<Cow<'a, str>>,
36{
37 fn from(value: T) -> Self {
38 Self::new(value)
39 }
40}
41
42impl Display for DeveloperId<'_> {
43 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
44 write!(f, "{}", &self.0)
45 }
46}
47
48#[derive(Default, Debug, Builder, Serialize, Clone)]
50#[builder(default, setter(into, strip_option))]
51#[serde(rename_all = "kebab-case")]
52pub struct Developers {
53 #[doc = r"Sorting options for results."]
54 orderby: Option<DevelopersSorting>,
55 #[doc = r"Sort direction"]
56 direction: Option<Direction>,
57}
58
59#[derive(Debug, Builder, Clone)]
61#[builder(setter(into, strip_option))]
62pub struct Developer<'a> {
63 #[doc = r"`ID` of the developer to retrieve"]
64 id: DeveloperId<'a>,
65}
66
67impl Developers {
68 pub fn builder() -> DevelopersBuilder {
70 DevelopersBuilder::default()
71 }
72}
73
74impl Developer<'_> {
75 pub fn builder<'a>() -> DeveloperBuilder<'a> {
77 DeveloperBuilder::default()
78 }
79}
80
81impl Default for DevelopersSorting {
82 fn default() -> Self {
83 Self::Name
84 }
85}
86
87impl Endpoint for Developers {
88 fn endpoint(&self) -> Cow<'static, str> {
89 "/developers".into()
90 }
91
92 fn query_parameters(&self) -> Result<QueryParams<'_>, BodyError> {
93 QueryParams::with(self)
94 }
95}
96
97impl Endpoint for Developer<'_> {
98 fn endpoint(&self) -> Cow<'static, str> {
99 format!("/developers/{}", self.id).into()
100 }
101}
102
103impl Pageable for Developers {}