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 url::Url;
pub mod git;
pub use self::git::Git;
use self::git::Ref;
const OCEAN_REGISTRY: &str = "https://registry.oceanpkg.org";
lazy_static! {
static ref OCEAN_REGISTRY_SOURCE: Source = Source::from_registry(
Url::parse(OCEAN_REGISTRY).unwrap()
);
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Source {
url: Url,
kind: Kind,
}
impl Source {
#[inline]
pub fn main_registry() -> &'static Self {
&OCEAN_REGISTRY_SOURCE
}
#[inline]
pub const fn from_registry(url: Url) -> Self {
Source { url, kind: Kind::Registry }
}
#[inline]
pub fn from_git(url: Url) -> Self {
Self::from_git_at(url, Ref::master())
}
#[inline]
pub const fn from_git_at(url: Url, reference: Ref) -> Self {
Source { url, kind: Kind::Git(reference) }
}
#[inline]
pub const fn url(&self) -> &Url {
&self.url
}
#[inline]
pub const fn kind(&self) -> &Kind {
&self.kind
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Kind {
Git(Ref),
Registry,
}