rtdlib/types/
http_url.rs

1
2use crate::types::*;
3use crate::errors::*;
4use uuid::Uuid;
5
6
7
8
9/// Contains an HTTP URL
10#[derive(Debug, Clone, Default, Serialize, Deserialize)]
11pub struct HttpUrl {
12  #[doc(hidden)]
13  #[serde(rename(serialize = "@type", deserialize = "@type"))]
14  td_name: String,
15  #[doc(hidden)]
16  #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
17  extra: Option<String>,
18  /// The URL
19  url: String,
20  
21}
22
23impl RObject for HttpUrl {
24  #[doc(hidden)] fn td_name(&self) -> &'static str { "httpUrl" }
25  #[doc(hidden)] fn extra(&self) -> Option<String> { self.extra.clone() }
26  fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
27}
28
29
30
31impl HttpUrl {
32  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
33  pub fn builder() -> RTDHttpUrlBuilder {
34    let mut inner = HttpUrl::default();
35    inner.td_name = "httpUrl".to_string();
36    inner.extra = Some(Uuid::new_v4().to_string());
37    RTDHttpUrlBuilder { inner }
38  }
39
40  pub fn url(&self) -> &String { &self.url }
41
42}
43
44#[doc(hidden)]
45pub struct RTDHttpUrlBuilder {
46  inner: HttpUrl
47}
48
49impl RTDHttpUrlBuilder {
50  pub fn build(&self) -> HttpUrl { self.inner.clone() }
51
52   
53  pub fn url<T: AsRef<str>>(&mut self, url: T) -> &mut Self {
54    self.inner.url = url.as_ref().to_string();
55    self
56  }
57
58}
59
60impl AsRef<HttpUrl> for HttpUrl {
61  fn as_ref(&self) -> &HttpUrl { self }
62}
63
64impl AsRef<HttpUrl> for RTDHttpUrlBuilder {
65  fn as_ref(&self) -> &HttpUrl { &self.inner }
66}
67
68
69