ogcapi_types/common/
link.rs

1use serde::{Deserialize, Serialize};
2
3/// Hyperlink to enable Hypermedia Access
4#[serde_with::skip_serializing_none]
5#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
6pub struct Link {
7    /// Supplies the URI to a remote resource (or resource fragment).
8    pub href: String,
9    /// The type or semantics of the relation.
10    pub rel: String,
11    /// A hint indicating what the media type of the result of dereferencing
12    /// the link should be.
13    pub r#type: Option<String>,
14    /// A hint indicating what the language of the result of dereferencing the
15    /// link should be.
16    pub hreflang: Option<String>,
17    /// Used to label the destination of a link such that it can be used as a
18    /// human-readable identifier.
19    pub title: Option<String>,
20    pub length: Option<i64>,
21}
22
23impl Link {
24    /// Constructs a new Link with the given href and link relation
25    pub fn new(href: impl ToString, rel: impl ToString) -> Link {
26        Link {
27            href: href.to_string(),
28            rel: rel.to_string(),
29            r#type: None,
30            hreflang: None,
31            title: None,
32            length: None,
33        }
34    }
35
36    /// Sets the media type of the Link and returns the Value
37    pub fn mediatype(mut self, mime: impl ToString) -> Link {
38        self.r#type = Some(mime.to_string());
39        self
40    }
41
42    /// Sets the language of the Link and returns the Value
43    pub fn language(mut self, language: impl ToString) -> Link {
44        self.hreflang = Some(language.to_string());
45        self
46    }
47
48    /// Sets the title of the Link and returns the Value
49    pub fn title(mut self, title: impl ToString) -> Link {
50        self.title = Some(title.to_string());
51        self
52    }
53
54    /// Sets the length of the reference resource by the Link and returns the Value
55    pub fn length(mut self, length: i64) -> Link {
56        self.length = Some(length);
57        self
58    }
59}