kitchen_fridge/
resource.rs

1use url::Url;
2
3/// Just a wrapper around a URL and credentials
4#[derive(Clone, Debug)]
5pub struct Resource {
6    url: Url,
7    username: String,
8    password: String,
9}
10
11impl Resource {
12    pub fn new(url: Url, username: String, password: String) -> Self {
13        Self { url, username, password }
14    }
15
16    pub fn url(&self) -> &Url { &self.url }
17    pub fn username(&self) -> &String { &self.username }
18    pub fn password(&self) -> &String { &self.password }
19
20    /// Build a new Resource by keeping the same credentials, scheme and server from `base` but changing the path part
21    pub fn combine(&self, new_path: &str) -> Resource {
22        let mut built = (*self).clone();
23        built.url.set_path(&new_path);
24        built
25    }
26}