fp_bindgen/serializable/
http.rs

1use super::Serializable;
2use crate::types::{CargoDependency, CustomType, Type, TypeIdent};
3use std::collections::{BTreeMap, BTreeSet};
4
5impl Serializable for http::Method {
6    fn ident() -> TypeIdent {
7        TypeIdent::from("Method")
8    }
9
10    fn ty() -> Type {
11        Type::Custom(CustomType {
12            ident: Self::ident(),
13            rs_ty: "http::Method".to_owned(),
14            rs_dependencies: http_dependencies(),
15            serde_attrs: vec![
16                "serialize_with = \"fp_bindgen_support::http::serialize_http_method\"".to_owned(),
17                "deserialize_with = \"fp_bindgen_support::http::deserialize_http_method\""
18                    .to_owned(),
19            ],
20            ts_ty: "Method".to_owned(),
21            ts_declaration: Some(
22                r#"
23    | "GET"
24    | "POST"
25    | "PUT"
26    | "DELETE"
27    | "HEAD"
28    | "OPTIONS"
29    | "CONNECT"
30    | "PATCH"
31    | "TRACE""#
32                    .to_owned(),
33            ),
34        })
35    }
36}
37
38impl Serializable for http::uri::Scheme {
39    fn ident() -> TypeIdent {
40        TypeIdent::from("Scheme")
41    }
42
43    fn ty() -> Type {
44        Type::Custom(CustomType {
45            ident: Self::ident(),
46            rs_ty: "http::Scheme".to_owned(),
47            rs_dependencies: http_dependencies(),
48            serde_attrs: vec![
49                "serialize_with = \"fp_bindgen_support::http::serialize_uri_scheme\"".to_owned(),
50                "deserialize_with = \"fp_bindgen_support::http::deserialize_uri_scheme\""
51                    .to_owned(),
52            ],
53            ts_ty: "Scheme".to_owned(),
54            ts_declaration: Some(r#""http" | "https""#.to_owned()),
55        })
56    }
57}
58
59impl Serializable for http::uri::Uri {
60    fn ident() -> TypeIdent {
61        TypeIdent::from("Uri")
62    }
63
64    fn ty() -> Type {
65        Type::Custom(CustomType {
66            ident: Self::ident(),
67            rs_ty: "http::Uri".to_owned(),
68            rs_dependencies: http_dependencies(),
69            serde_attrs: vec![
70                "serialize_with = \"fp_bindgen_support::http::serialize_uri\"".to_owned(),
71                "deserialize_with = \"fp_bindgen_support::http::deserialize_uri\"".to_owned(),
72            ],
73            ts_ty: "string".to_owned(),
74            ts_declaration: None,
75        })
76    }
77}
78
79impl Serializable for http::HeaderMap {
80    fn ident() -> TypeIdent {
81        TypeIdent::from("http::HeaderMap")
82    }
83
84    fn ty() -> Type {
85        Type::Custom(CustomType {
86            ident: Self::ident(),
87            rs_ty: "http::HeaderMap".to_owned(),
88            rs_dependencies: http_dependencies(),
89            serde_attrs: vec![
90                "serialize_with = \"fp_bindgen_support::http::serialize_header_map\"".to_owned(),
91                "deserialize_with = \"fp_bindgen_support::http::deserialize_header_map\""
92                    .to_owned(),
93            ],
94            ts_ty: "HeaderMap".to_owned(),
95            ts_declaration: Some(r#"{ [key: string]: Uint8Array }"#.into()),
96        })
97    }
98}
99
100fn http_dependencies() -> BTreeMap<&'static str, CargoDependency> {
101    BTreeMap::from([
102        (
103            "fp-bindgen-support",
104            CargoDependency {
105                version: Some(env!("CARGO_PKG_VERSION")),
106                features: BTreeSet::from(["http"]),
107                ..Default::default()
108            },
109        ),
110        ("http", CargoDependency::with_version("0.2")),
111    ])
112}