summary refs log tree commit diff stats
path: root/src/data/sources/defaults.rs
blob: e8ffa334121150307262858fdb55f7c86cd87bb2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
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 <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()
            }
        }
    }
}