nmd_core/resource/
remote_resource.rs1use std::str::FromStr;
2
3use url::Url;
4
5use super::{Resource, ResourceError};
6
7
8
9pub struct RemoteResource {
11 url: Url
12}
13
14impl RemoteResource {
15
16 pub fn is_valid_remote_resource(s: &str) -> bool {
17
18 Self::is_valid_url(s)
19 }
20
21 fn is_valid_url(s: &str) -> bool {
22 match reqwest::Url::parse(s) {
23 Ok(_) => true,
24 Err(_) => false,
25 }
26 }
27}
28
29impl FromStr for RemoteResource {
30 type Err = ResourceError;
31
32 fn from_str(url: &str) -> Result<Self, Self::Err> {
33 if !Self::is_valid_url(url) {
34 return Err(ResourceError::InvalidResourceVerbose(format!("{} is an invalid url", url)))
35 }
36
37 match Url::parse(url) {
38 Ok(url) => Ok(Self {
39 url
40 }),
41 Err(_) => Err(ResourceError::InvalidResourceVerbose(format!("{} is an invalid url", url)))
42 }
43
44 }
45}
46
47impl Resource for RemoteResource {
48 type LocationType = Url;
49
50 fn write(&mut self, _content: &str) -> Result<(), super::ResourceError> {
51 todo!()
52 }
53
54 fn append(&mut self, _content: &str) -> Result<(), super::ResourceError> {
55 todo!()
56 }
57
58 fn read(&self) -> Result<String, super::ResourceError> {
59 todo!()
60 }
61
62 fn name(&self) -> &String {
63 todo!()
64 }
65
66 fn location(&self) -> &Self::LocationType {
67 &self.url
68 }
69
70 fn erase(&mut self) -> Result<(), ResourceError> {
71 todo!()
72 }
73}