diff options
Diffstat (limited to 'src/data/kinds.rs')
-rw-r--r-- | src/data/kinds.rs | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/src/data/kinds.rs b/src/data/kinds.rs new file mode 100644 index 0000000..d492a92 --- /dev/null +++ b/src/data/kinds.rs @@ -0,0 +1,96 @@ +// This file is part of GAnarchy - decentralized development hub +// Copyright (C) 2021 Soni L. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see <https://www.gnu.org/licenses/>. + +//! Kinds of data for use with `DataSource`. + +use arcstr::ArcStr; + +use url::Url; + +use super::Kind; +use super::OverridableKind; + +/// Title of an instance. +#[derive(Clone, Eq, Hash, Ord, PartialEq, PartialOrd)] +pub struct InstanceTitle(pub String); + +impl Kind for InstanceTitle { + /// A source may only have one `InstanceTitle`. + type Values = Option<Self>; +} + +/// URL of an instance. +#[derive(Clone, Eq, Hash, Ord, PartialEq, PartialOrd)] +pub struct InstanceBaseUrl(pub Url); + +impl Kind for InstanceBaseUrl { + /// A source may only have one `InstanceBaseUrl`. + type Values = Option<Self>; +} + +/// URL of a repo list. +#[derive(Clone, Eq, Hash, Ord, PartialEq, PartialOrd)] +pub struct RepoListUrl { + // `Url` is actually fairly expensive, but we don't usually have a lot of + // `RepoListUrl` around. Additionally these are generally unique. + /// The actual URL that references a repo list. + pub url: Url, + /// Whether this entry is active. + pub active: bool, + /// Whether this repo list is allowed to have negative entries. + pub allow_negative_entries: bool, +} + +impl Kind for RepoListUrl { + /// A source may have many `RepoListUrl`. + type Values = Vec<Self>; +} + +impl OverridableKind for RepoListUrl { + type Key = Url; + + fn as_key(&self) -> &Self::Key { + &self.url + } +} + +/// The key for a [`ProjectFork`]. +#[derive(Clone, Eq, Hash, Ord, PartialEq, PartialOrd)] +pub struct ProjectForkKey { + project: ArcStr, + url: ArcStr, + branch: ArcStr, +} + +/// A fork of a project. +#[derive(Clone, Eq, Hash, Ord, PartialEq, PartialOrd)] +pub struct ProjectFork { + pub key: ProjectForkKey, + pub active: bool, +} + +impl Kind for ProjectFork { + /// A source may have many `ProjectFork`. + type Values = Vec<Self>; +} + +impl OverridableKind for ProjectFork { + type Key = ProjectForkKey; + + fn as_key(&self) -> &Self::Key { + &self.key + } +} |