aboutsummaryrefslogtreecommitdiff
path: root/lockchain-core/src/initialise.rs
blob: 6ae48a9386849052ec06263505ccf3724c42e5b0 (plain)
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
//! A shared initialisation block for vaults
//!
//! All vaults, regardless of backends
//! or persistence layer
//! share the same common principles
//! of users and permissions.
//!
//! This means that intiailisation is shared,
//! regardless of what backend implements it.
//!
//! A `VaultGenerator` takes arguments
//! for a generic backend,
//! calls functions provided by said backend
//! and then returns the actual backend.

use traits::{Body, Vault};

/// A generator is initialised with a generic backend
/// which can then chain-call functions to setup the
/// base functionality of a Vault, and then yield
/// a working and initialised instance of the
/// generic vault backend.
pub struct Generator {
    #[doc(hidden)]
    pub name: Option<String>,
    #[doc(hidden)]
    pub location: Option<String>,
}

impl Generator {
    /// Start a new generator for a generic type
    pub fn new() -> Self {
        Self {
            name: None,
            location: None,
        }
    }

    pub fn path<S: Into<String>>(self, name: S, location: S) -> Self {
        Self {
            name: Some(name.into()),
            location: Some(location.into()),
            ..self
        }
    }

    /// Finally call this function to construct the vault
    pub fn finalise<V, B>(self) -> V
    where
        V: Vault<B>,
        B: Body,
    {
        V::new(self)
    }
}