From 22e7a62e9529cc4a59941e8342f69d0f6ded60f9 Mon Sep 17 00:00:00 2001 From: SoniEx2 Date: Mon, 13 Sep 2021 23:08:19 -0300 Subject: Mostly finish data source interactions --- src/data/sources/defaults.rs | 107 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 src/data/sources/defaults.rs (limited to 'src/data/sources/defaults.rs') diff --git a/src/data/sources/defaults.rs b/src/data/sources/defaults.rs new file mode 100644 index 0000000..e8ffa33 --- /dev/null +++ b/src/data/sources/defaults.rs @@ -0,0 +1,107 @@ +// 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 . + +//! 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, + Result<(), Box>, + ) { + (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 { + fn get_values(&self) -> Option { + None + } + } + + /// Default [`InstanceBaseUrl`] source. Always `None`. + impl trait DataSource { + fn get_values(&self) -> Option { + None + } + } + + /// Default [`RepoListUrl`] source. + impl trait DataSource { + fn get_values(&self) -> Vec { + // Forks may wish to add stuff here. + vec![ + ] + } + } + + /// Default [`ProjectFork`] source. + impl trait DataSource> { + fn get_values(&self) -> BTreeSet> { + // 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() + } + } + } +} -- cgit 1.4.1