summary refs log blame commit diff stats
path: root/src/data/sources/defaults.rs
blob: 7db9e48d0fae3ca451d5943801820f0242abe46b (plain) (tree)


















                                                                              











                                           
                         

















                                                    
                                         
                                   

                                            
















































                                                                             
// 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 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<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()
            }
        }
    }
}