summaryrefslogtreecommitdiff
path: root/crates/arti-relay/src/builder.rs
blob: 96c20d81a8e43b1ecd7b7a61a1777f6929da61d5 (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
//! Types for conveniently constructing a TorRelay.

use tor_rtcompat::Runtime;

use crate::config::TorRelayConfig;
use crate::err::Error;
use crate::relay::TorRelay;

/// An object for constructing a [`TorRelay`].
///
/// Returned by [`TorRelay::builder()`].
#[derive(Clone)]
#[must_use]
#[allow(unused)] // TODO: Remove me when used.
pub(crate) struct TorRelayBuilder<R: Runtime> {
    /// The runtime for the client to use
    runtime: R,
    /// The configuration.
    config: TorRelayConfig,
}

#[allow(unused)] // TODO: Remove me when used.
impl<R: Runtime> TorRelayBuilder<R> {
    /// Construct a new TorClientBuilder with the given runtime.
    pub(crate) fn new(runtime: R) -> Self {
        Self {
            runtime,
            config: TorRelayConfig::default(),
        }
    }

    /// Return a newly created TorRelay object.
    pub(crate) fn create(&self) -> Result<TorRelay<R>, Error> {
        TorRelay::create_inner(self.runtime.clone(), &self.config).map_err(Into::into)
    }
}