graph_http/
resource_identifier.rs

1use graph_core::resource::ResourceIdentity;
2use url::Url;
3
4pub trait ResourceIdentifier {
5    fn resource_identifier() -> ResourceIdentity;
6}
7
8/// Provides components for storing resource id's and helps build the current request URL.
9#[derive(Clone, Debug, Eq, PartialEq)]
10pub struct ResourceConfig {
11    pub resource_identity: ResourceIdentity,
12    pub url: Url,
13    pub resource_identity_id: Option<String>,
14}
15
16impl ResourceConfig {
17    pub fn new(
18        resource_identity: ResourceIdentity,
19        url: Url,
20        resource_identity_id: Option<String>,
21    ) -> ResourceConfig {
22        ResourceConfig {
23            resource_identity,
24            url,
25            resource_identity_id,
26        }
27    }
28}
29
30impl ResourceConfig {
31    pub fn resource_identity(&self) -> ResourceIdentity {
32        self.resource_identity
33    }
34
35    pub fn extend_path<I: AsRef<str>>(&mut self, path: &[I]) {
36        if let Ok(mut p) = self.url.path_segments_mut() {
37            p.extend(path);
38        }
39    }
40}
41
42impl AsRef<Url> for ResourceConfig {
43    fn as_ref(&self) -> &Url {
44        &self.url
45    }
46}
47
48impl AsMut<Url> for ResourceConfig {
49    fn as_mut(&mut self) -> &mut Url {
50        &mut self.url
51    }
52}