summaryrefslogtreecommitdiff
path: root/dhall_syntax/src/import.rs
blob: 00f293c8d7db3a8ac95e01cc670c4b4f8dd7cf01 (plain)
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
use std::path::PathBuf;

/// The beginning of a file path which anchors subsequent path components
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum FilePrefix {
    /// Absolute path
    Absolute,
    /// Path relative to .
    Here,
    /// Path relative to ..
    Parent,
    /// Path relative to ~
    Home,
}

/// The location of import (i.e. local vs. remote vs. environment)
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ImportLocation {
    Local(FilePrefix, PathBuf),
    Remote(URL),
    Env(String),
    Missing,
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct URL {
    pub scheme: Scheme,
    pub authority: String,
    pub path: PathBuf,
    pub query: Option<String>,
    pub headers: Option<Box<ImportHashed>>,
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum Scheme {
    HTTP,
    HTTPS,
}

/// How to interpret the import's contents (i.e. as Dhall code or raw text)
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum ImportMode {
    Code,
    RawText,
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Hash {
    pub protocol: String,
    pub hash: String,
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ImportHashed {
    pub location: ImportLocation,
    pub hash: Option<Hash>,
}

/// Reference to an external resource
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Import {
    pub mode: ImportMode,
    pub location_hashed: ImportHashed,
}