1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use ident_case::RenameRule;
use serde::{Deserialize, Serialize};
use std::{fmt, str};
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct App(String);
impl AsRef<str> for App {
fn as_ref(&self) -> &str {
self.0.as_ref()
}
}
impl fmt::Display for App {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}
impl str::FromStr for App {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(App(s.to_owned()))
}
}
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct Author(String);
impl AsRef<str> for Author {
fn as_ref(&self) -> &str {
self.0.as_ref()
}
}
impl From<String> for Author {
fn from(s: String) -> Author {
Author(s)
}
}
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct Type(String);
impl AsRef<str> for Type {
fn as_ref(&self) -> &str {
self.0.as_ref()
}
}
impl Type {
pub fn from_camel_case<S>(s: S) -> Type
where
S: ToString,
{
Type(s.to_string())
}
pub fn from_snake_case<S>(s: S) -> Type
where
S: AsRef<str>,
{
Type(RenameRule::PascalCase.apply_to_field(s))
}
}