#![allow(missing_docs, clippy::missing_docs_in_private_items)]
use crate::{err::ErrorDetail, BootstrapBehavior, Result, TorClient, TorClientConfig};
use tor_rtcompat::Runtime;
#[derive(Debug, Clone)]
#[must_use]
pub struct TorClientBuilder<R> {
runtime: R,
config: TorClientConfig,
bootstrap_behavior: BootstrapBehavior,
}
impl<R> TorClientBuilder<R> {
pub(crate) fn new(runtime: R) -> Self {
Self {
runtime,
config: TorClientConfig::default(),
bootstrap_behavior: BootstrapBehavior::default(),
}
}
pub fn config(mut self, config: TorClientConfig) -> Self {
self.config = config;
self
}
pub fn bootstrap_behavior(mut self, bootstrap_behavior: BootstrapBehavior) -> Self {
self.bootstrap_behavior = bootstrap_behavior;
self
}
}
impl<R: Runtime> TorClientBuilder<R> {
pub fn create_unbootstrapped(self) -> Result<TorClient<R>> {
TorClient::create_inner(self.runtime, self.config, self.bootstrap_behavior)
.map_err(ErrorDetail::into)
}
pub async fn create_bootstrapped(self) -> Result<TorClient<R>> {
let r = self.create_unbootstrapped()?;
r.bootstrap().await?;
Ok(r)
}
}