// 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 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, }; use super::super::Update; /// 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 with no stats. impl trait DataSourceBase { fn update(&mut self) -> Update { Update::default() } 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() } } } }