oceanpkg/drop/
mod.rs

1//! Ocean packages, also known as drops 💧.
2
3#[cfg(feature = "toml")]
4mod package;
5
6pub mod kind;
7pub mod license;
8pub mod manifest;
9pub mod name;
10pub mod source;
11pub mod version;
12
13use self::kind::{App, Exe, Font, Lib};
14
15#[doc(inline)]
16pub use self::{
17    kind::Kind,
18    license::License,
19    manifest::Manifest,
20    name::Name,
21    source::Source,
22    version::Version,
23};
24
25#[cfg(feature = "toml")]
26#[doc(inline)]
27pub use self::{
28    package::*,
29};
30
31/// Defines an Ocean package, also known as a drop 💧.
32#[derive(Clone, Debug)]
33pub enum Drop {
34    /// A package with a graphical interface.
35    App(App),
36    /// A package that can be executed; e.g. CLI tool or script.
37    Exe(Exe),
38    /// A package for a typeface with specific properties; e.g. bold, italic.
39    Font(Font),
40    /// A package for a library of a given language.
41    Lib(Lib),
42}
43
44impl From<App> for Drop {
45    #[inline]
46    fn from(drop: App) -> Self {
47        Self::App(drop)
48    }
49}
50
51impl From<Exe> for Drop {
52    #[inline]
53    fn from(drop: Exe) -> Self {
54        Self::Exe(drop)
55    }
56}
57
58impl From<Font> for Drop {
59    #[inline]
60    fn from(drop: Font) -> Self {
61        Self::Font(drop)
62    }
63}
64
65impl From<Lib> for Drop {
66    #[inline]
67    fn from(drop: Lib) -> Self {
68        Self::Lib(drop)
69    }
70}
71
72impl Drop {
73    ///
74    pub fn query<S>(query: &name::Query<S>) -> Result<Self, ()>
75        where S: AsRef<str>
76    {
77        let query = query.to_ref::<str>();
78        unimplemented!("TODO: Find '{}' drop", query);
79    }
80
81    /// Returns the kind of drop.
82    pub fn kind(&self) -> Kind {
83        match self {
84            Self::App(_)  => Kind::App,
85            Self::Exe(_)  => Kind::Exe,
86            Self::Font(_) => Kind::Font,
87            Self::Lib(_)  => Kind::Lib,
88        }
89    }
90
91    /// Returns basic metadata for the drop.
92    pub fn metadata(&self) -> &Metadata {
93        match self {
94            Self::App(app)   => app.metadata(),
95            Self::Exe(exe)   => exe.metadata(),
96            Self::Font(font) => font.metadata(),
97            Self::Lib(lib)   => lib.metadata(),
98        }
99    }
100}
101
102/// Information common to all drops.
103#[derive(Clone, Debug)]
104pub struct Metadata {
105    // TODO: Replace `scope` and `name` with a `ScopedNameRef`
106
107    /// The drop's namespace.
108    pub scope: String,
109    /// The drop's unique name within its namespace.
110    pub name: String,
111}