1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
use std::str::FromStr;

use url::Url;

use super::{Resource, ResourceError};



/// Remote resource based on URL
pub struct RemoteResource {
    url: Url
}

impl RemoteResource {

    pub fn is_valid_remote_resource(s: &str) -> bool {
        Self::is_valid_url(s)
    }

    fn is_valid_url(s: &str) -> bool {
        match reqwest::Url::parse(s) {
            Ok(_) => true,
            Err(_) => false,
        }
    }
}

impl FromStr for RemoteResource {
    type Err = ResourceError;

    fn from_str(url: &str) -> Result<Self, Self::Err> {
        if !Self::is_valid_url(url) {
            return Err(ResourceError::InvalidResourceVerbose(format!("{} is an invalid url", url)))
        }

        match Url::parse(url) {
            Ok(url) => Ok(Self {
                url
            }),
            Err(_) => Err(ResourceError::InvalidResourceVerbose(format!("{} is an invalid url", url)))
        }
        
    }
}

impl Resource for RemoteResource {
    type LocationType = Url;

    fn write(&mut self, _content: &str) -> Result<(), super::ResourceError> {
        todo!()
    }

    fn append(&mut self, _content: &str) -> Result<(), super::ResourceError> {
        todo!()
    }

    fn read(&self) -> Result<String, super::ResourceError> {
        todo!()
    }

    fn name(&self) -> &String {
        todo!()
    }

    fn location(&self) -> &Self::LocationType {
        &self.url
    }

    fn erase(&mut self) -> Result<(), ResourceError> {
        todo!()
    }
}