tor_dirserver/
mirror.rs

1//! The Tor directory mirror implementation.
2
3use crate::err::BuilderError;
4use std::path::PathBuf;
5
6/// Core data type of a directory mirror.
7#[derive(Debug)]
8pub struct DirMirror {
9    /// Access to the [`DirMirrorBuilder`].
10    builder: DirMirrorBuilder,
11}
12
13/// Builder type for [`DirMirror`].
14#[derive(Debug, Default)]
15pub struct DirMirrorBuilder {
16    /// The path to the SQLite database.
17    db_path: Option<PathBuf>,
18}
19
20impl DirMirror {
21    /// Returns a new [`DirMirrorBuilder`] with default values.
22    pub fn builder() -> DirMirrorBuilder {
23        DirMirrorBuilder::default()
24    }
25}
26
27impl DirMirrorBuilder {
28    /// Creates a new instance of a [`DirMirrorBuilder`].
29    pub fn new() -> Self {
30        Self::default()
31    }
32
33    /// Sets the path of the SQLite database to a path on the filesystem.
34    pub fn set_db_path(mut self, db_path: PathBuf) -> Self {
35        self.db_path = Some(db_path);
36        self
37    }
38
39    /// Builds a [`DirMirror`] from a [`DirMirrorBuilder`].
40    pub fn build(self) -> Result<DirMirror, BuilderError> {
41        if self.db_path.is_none() {
42            return Err(BuilderError::MissingField("db_path"));
43        }
44
45        Ok(DirMirror { builder: self })
46    }
47}