oceanpkg/drop/source/
mod.rs

1//! The source of a package.
2
3use url::Url;
4
5pub mod git;
6
7pub use self::git::Git;
8
9use self::git::Ref;
10
11const OCEAN_REGISTRY: &str = "https://registry.oceanpkg.org";
12
13lazy_static! {
14    static ref OCEAN_REGISTRY_SOURCE: Source = Source::from_registry(
15        Url::parse(OCEAN_REGISTRY).unwrap()
16    );
17}
18
19/// The source of a drop.
20#[derive(Clone, Debug, PartialEq, Eq)]
21pub struct Source {
22    url: Url,
23    kind: Kind,
24}
25
26impl Source {
27    /// A drop source for the main Ocean registry.
28    #[inline]
29    pub fn main_registry() -> &'static Self {
30        &OCEAN_REGISTRY_SOURCE
31    }
32
33    /// A drop source at a `Url` for an Ocean registry.
34    #[inline]
35    pub const fn from_registry(url: Url) -> Self {
36        Source { url, kind: Kind::Registry }
37    }
38
39    /// A drop source at a `Url` for to a git repository.
40    #[inline]
41    pub fn from_git(url: Url) -> Self {
42        Self::from_git_at(url, Ref::master())
43    }
44
45    /// A drop source at a `Url` for a git repository at a specific reference.
46    #[inline]
47    pub const fn from_git_at(url: Url, reference: Ref) -> Self {
48        Source { url, kind: Kind::Git(reference) }
49    }
50
51    /// Where this source is located.
52    #[inline]
53    pub const fn url(&self) -> &Url {
54        &self.url
55    }
56
57    /// The type of source.
58    #[inline]
59    pub const fn kind(&self) -> &Kind {
60        &self.kind
61    }
62}
63
64/// Determines how to treat a [`Source`](struct.Source.html).
65#[derive(Clone, Debug, PartialEq, Eq)]
66pub enum Kind {
67    /// The drop is located in a git repository and the given reference should
68    /// be used.
69    Git(Ref),
70    /// The drop is located in a registry.
71    Registry,
72}