|
| 1 | +use serde::{Deserialize, Serialize}; |
| 2 | +use std::{collections::BTreeMap, collections::HashMap}; |
| 3 | + |
| 4 | +pub type Body = serde_bytes::ByteBuf; |
| 5 | + |
| 6 | +pub type ComplexAlias = ComplexGuestToHost; |
| 7 | + |
| 8 | +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] |
| 9 | +pub struct ComplexGuestToHost { |
| 10 | + pub simple: Simple, |
| 11 | + pub map: BTreeMap<String, Simple>, |
| 12 | +} |
| 13 | + |
| 14 | +/// Multi-line doc comment with complex characters |
| 15 | +/// & " , \ ! ' |
| 16 | +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] |
| 17 | +#[serde(rename_all = "camelCase")] |
| 18 | +pub struct ComplexHostToGuest { |
| 19 | + #[serde(flatten)] |
| 20 | + pub simple: Simple, |
| 21 | + pub list: Vec<f64>, |
| 22 | + pub points: Vec<Point<f64>>, |
| 23 | + pub recursive: Vec<Point<Point<f64>>>, |
| 24 | + #[serde(default, skip_serializing_if = "Option::is_none")] |
| 25 | + pub complex_nested: Option<BTreeMap<String, Vec<FloatingPoint>>>, |
| 26 | + |
| 27 | + /// Raw identifiers are supported too. |
| 28 | + pub r#type: String, |
| 29 | + pub value: Value, |
| 30 | +} |
| 31 | + |
| 32 | +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] |
| 33 | +pub struct ExplicitedlyImportedType { |
| 34 | + pub you_will_see_this: bool, |
| 35 | +} |
| 36 | + |
| 37 | +pub type FloatingPoint = Point<f64>; |
| 38 | + |
| 39 | +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] |
| 40 | +pub struct GroupImportedType1 { |
| 41 | + pub you_will_see_this: bool, |
| 42 | +} |
| 43 | + |
| 44 | +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] |
| 45 | +pub struct GroupImportedType2 { |
| 46 | + pub you_will_see_this: bool, |
| 47 | +} |
| 48 | + |
| 49 | +/// Similar to the `RequestOptions` struct, but using types from the `http` crate. |
| 50 | +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] |
| 51 | +#[serde(rename_all = "camelCase")] |
| 52 | +pub struct HttpRequestOptions { |
| 53 | + #[serde(deserialize_with = "fp_bindgen_support::http::deserialize_uri", serialize_with = "fp_bindgen_support::http::serialize_uri")] |
| 54 | + pub url: http::Uri, |
| 55 | + #[serde(deserialize_with = "fp_bindgen_support::http::deserialize_http_method", serialize_with = "fp_bindgen_support::http::serialize_http_method")] |
| 56 | + pub method: http::Method, |
| 57 | + pub headers: HashMap<String, String>, |
| 58 | + #[serde(default, skip_serializing_if = "Option::is_none")] |
| 59 | + pub body: Option<serde_bytes::ByteBuf>, |
| 60 | +} |
| 61 | + |
| 62 | +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] |
| 63 | +#[serde(rename_all = "PascalCase")] |
| 64 | +pub struct Point<T> { |
| 65 | + pub value: T, |
| 66 | +} |
| 67 | + |
| 68 | +/// Represents an error with the request. |
| 69 | +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] |
| 70 | +#[serde(tag = "type", rename_all = "snake_case")] |
| 71 | +pub enum RequestError { |
| 72 | + /// Used when we know we don't have an active network connection. |
| 73 | + Offline, |
| 74 | + NoRoute, |
| 75 | + ConnectionRefused, |
| 76 | + Timeout, |
| 77 | + #[serde(rename_all = "snake_case")] |
| 78 | + ServerError { |
| 79 | + /// HTTP status code. |
| 80 | + status_code: u16, |
| 81 | + |
| 82 | + /// Response body. |
| 83 | + response: Body, |
| 84 | + }, |
| 85 | + /// Misc. |
| 86 | + #[serde(rename = "other/misc")] |
| 87 | + Other { reason: String }, |
| 88 | +} |
| 89 | + |
| 90 | +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] |
| 91 | +#[serde(rename_all = "SCREAMING_SNAKE_CASE")] |
| 92 | +pub enum RequestMethod { |
| 93 | + Delete, |
| 94 | + Get, |
| 95 | + Options, |
| 96 | + Post, |
| 97 | + Put, |
| 98 | +} |
| 99 | + |
| 100 | +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] |
| 101 | +#[serde(rename_all = "camelCase")] |
| 102 | +pub struct RequestOptions { |
| 103 | + pub url: String, |
| 104 | + pub method: RequestMethod, |
| 105 | + pub headers: HashMap<String, String>, |
| 106 | + #[serde(default, skip_serializing_if = "Option::is_none")] |
| 107 | + pub body: Option<serde_bytes::ByteBuf>, |
| 108 | +} |
| 109 | + |
| 110 | +/// A response to a request. |
| 111 | +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] |
| 112 | +#[serde(rename_all = "camelCase")] |
| 113 | +pub struct Response { |
| 114 | + /// Response headers, by name. |
| 115 | + pub headers: HashMap<String, String>, |
| 116 | + |
| 117 | + /// Response body. |
| 118 | + pub body: Body, |
| 119 | +} |
| 120 | + |
| 121 | +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] |
| 122 | +pub struct Simple { |
| 123 | + pub foo: i32, |
| 124 | + pub bar: String, |
| 125 | +} |
| 126 | + |
| 127 | +/// Tagged dynamic value. |
| 128 | +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] |
| 129 | +pub enum Value { |
| 130 | + Integer(i64), |
| 131 | + Float(f64), |
| 132 | + List(Vec<Value>), |
| 133 | + Map(BTreeMap<String, Value>), |
| 134 | +} |
0 commit comments