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
#![deny(rust_2018_idioms)]

#[cfg(any(feature = "android", target_os = "android"))]
pub mod android;
#[cfg(any(feature = "ios", target_os = "ios"))]
pub mod ios;
#[cfg(any(feature = "linux", target_os = "linux"))]
pub mod linux;
#[cfg(any(feature = "macos", target_os = "macos", target_os = "ios"))]
pub mod macos;
#[cfg(any(feature = "windows", target_os = "windows"))]
pub mod windows;
pub mod xdg;

#[cfg(target_os = "android")]
pub use android::system;
#[cfg(target_os = "ios")]
pub use ios::system;
#[cfg(target_os = "linux")]
pub use linux::system;
#[cfg(target_os = "macos")]
pub use macos::system;
#[cfg(windows)]
pub use windows::system;

#[cfg(target_os = "android")]
pub use android::user;
#[cfg(target_os = "ios")]
pub use ios::user;
#[cfg(target_os = "linux")]
pub use linux::user;
#[cfg(target_os = "macos")]
pub use macos::user;
#[cfg(windows)]
pub use windows::user;

#[derive(Debug, thiserror::Error)]
pub enum ResolveError {
    #[error("IRI does not have `container` or `file` scheme. Got: {0}")]
    InvalidScheme(String),

    #[error("IRI is empty")]
    EmptyIri,

    #[error("{0}")]
    PlatformSpecific(String),
}

pub(crate) fn file_path<P: AsRef<std::path::Path>>(path: P) -> iref::IriBuf {
    let path = path
        .as_ref()
        .to_string_lossy()
        .replace(r"\", "/")
        .replace(" ", "%20");
    iref::IriBuf::new(&format!("file:///{}", path)).expect("invalid IRI")
}