lib_humus/templating/
api_format.rs1use mime::Mime;
6use tinystr::tinystr;
7
8use crate::templating::HumusFormatIdentifier;
9
10pub trait HumusApiFormat: Clone + Send {
14 fn get_name(&self) -> HumusFormatIdentifier;
16
17 fn get_media_type(&self) -> Mime;
19
20 fn from_name(name: &HumusFormatIdentifier) -> Option<Self>;
22
23 fn get_all() -> Vec<Self>;
25}
26
27#[derive(Clone)]
29pub struct JsonOnlyApiFormat;
30
31impl HumusApiFormat for JsonOnlyApiFormat {
32 fn get_name(&self) -> HumusFormatIdentifier {
33 tinystr!(16, "json")
34 }
35
36 fn get_media_type(&self) -> Mime {
37 mime::APPLICATION_JSON
38 }
39
40 fn from_name(name: &HumusFormatIdentifier) -> Option<Self> {
41 match name.as_str() {
42 "json" => Some(Self),
43 _ => None,
44 }
45 }
46
47 fn get_all() -> Vec<Self> {
48 vec![Self]
49 }
50}