Skip to content

Commit

Permalink
Refactor tor API to support flexible path handling
Browse files Browse the repository at this point in the history
  • Loading branch information
yukibtc committed Dec 16, 2024
1 parent 2ef2b4e commit 259c0bc
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#[cfg(all(feature = "socks", not(target_arch = "wasm32")))]
use std::net::SocketAddr;
#[cfg(all(feature = "tor", not(target_arch = "wasm32")))]
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::time::Duration;

pub use futures_util;
Expand Down Expand Up @@ -60,27 +60,26 @@ impl ConnectionMode {
}

/// Embedded tor client
///
/// This not work on `android` and/or `ios` targets.
/// Use [`Connection::tor_with_path`] instead.
#[inline]
#[cfg(all(
feature = "tor",
not(target_arch = "wasm32"),
not(target_os = "android"),
not(target_os = "ios"),
))]
#[cfg(all(feature = "tor", not(target_arch = "wasm32")))]
pub fn tor() -> Self {
Self::Tor { custom_path: None }
}

/// Embedded tor client
///
/// Specify a path where to store data
#[inline]
#[cfg(all(
feature = "tor",
not(target_arch = "wasm32"),
any(target_os = "android", target_os = "ios")
))]
pub fn tor(data_path: PathBuf) -> Self {
#[cfg(all(feature = "tor", not(target_arch = "wasm32")))]
pub fn tor_with_path<P>(data_path: P) -> Self
where
P: AsRef<Path>,
{
Self::Tor {
custom_path: Some(data_path),
custom_path: Some(data_path.as_ref().to_path_buf()),
}
}
}
Expand Down

0 comments on commit 259c0bc

Please sign in to comment.