// 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/>.
//! Data source for compile-time defaults.
use std::collections::BTreeSet;
use std::error;
use std::time::Duration;
use impl_trait::impl_trait;
use super::super::DataSource;
use super::super::DataSourceBase;
use super::super::effective::EffectiveKind;
use super::super::kinds::{
InstanceBaseUrl,
InstanceTitle,
ProjectFork,
RepoListUrl,
};
/// Data source that provides compile-time defaults.
///
/// # Examples
///
/// Constructing a `DefaultsDataSource`:
///
/// ```rust
/// use ganarchy::data::sources::DefaultsDataSource;
///
/// let x = DefaultsDataSource;
/// # let _ = x;
/// ```
#[derive(Copy, Clone, Debug, Default)]
pub struct DefaultsDataSource;
impl_trait! {
impl DefaultsDataSource {
/// Always updates successfully, with an unknown refresh interval.
impl trait DataSourceBase {
fn update(&mut self) -> (
Option<Duration>,
Result<(), Box<dyn error::Error + Send + Sync + 'static>>,
) {
(None, Ok(()))
}
fn exists(&self) -> bool {
true
}
}
impl trait std::fmt::Display {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "compile-time defaults")
}
}
/// Default [`InstanceTitle`] source. Always `None`.
impl trait DataSource<InstanceTitle> {
fn get_values(&self) -> Option<InstanceTitle> {
None
}
}
/// Default [`InstanceBaseUrl`] source. Always `None`.
impl trait DataSource<InstanceBaseUrl> {
fn get_values(&self) -> Option<InstanceBaseUrl> {
None
}
}
/// Default [`RepoListUrl`] source.
impl trait DataSource<RepoListUrl> {
fn get_values(&self) -> Vec<RepoListUrl> {
// Forks may wish to add stuff here.
vec![
]
}
}
/// Default [`ProjectFork`] source.
impl trait DataSource<EffectiveKind<ProjectFork>> {
fn get_values(&self) -> BTreeSet<EffectiveKind<ProjectFork>> {
// Forks may wish to add stuff here.
// In particular, as this DataSource is a kind of config,
// these override external repo lists (but not local config),
// including for setting certain repos to off.
vec![
].into_iter().collect()
}
}
}
}