tor-config: Make ItemOrBool an experimental feature.

This commit is contained in:
Gabriela Moldovan 2023-06-29 14:28:53 +01:00
parent 373fd6acd2
commit 26eefdc564
4 changed files with 35 additions and 3 deletions

View File

@ -85,6 +85,7 @@ experimental = [
"tor-netdoc/experimental",
"tor-dirmgr/experimental",
"tor-circmgr/experimental",
"tor-config/experimental",
]
# Enable experimental APIs that are not yet officially supported.

View File

@ -15,7 +15,7 @@ pub use tor_config::convert_helper_via_multi_line_list_builder;
pub use tor_config::impl_standard_builder;
pub use tor_config::list_builder::{MultilineListBuilder, MultilineListBuilderError};
pub use tor_config::{define_list_builder_accessors, define_list_builder_helper};
pub use tor_config::{BoolOrAuto, ConfigError, ItemOrBool};
pub use tor_config::{BoolOrAuto, ConfigError};
pub use tor_config::{CfgPath, CfgPathError, ConfigBuildError, ConfigurationSource, Reconfigure};
pub use tor_guardmgr::bridge::BridgeConfigBuilder;
@ -24,6 +24,9 @@ pub use tor_guardmgr::bridge::BridgeConfigBuilder;
#[cfg_attr(docsrs, doc(cfg(feature = "bridge-client")))]
pub use tor_guardmgr::bridge::BridgeParseError;
#[cfg(feature = "experimental-api")]
pub use tor_config::ItemOrBool;
use tor_guardmgr::bridge::BridgeConfig;
/// Types for configuring how Tor circuits are built.
@ -190,7 +193,7 @@ impl_standard_builder! { StorageConfig }
/// Deserialize the `keystore_dir` storage field.
///
/// NOTE: The first option is needed because of the builder, the second is the actual type of the field.
#[cfg(feature = "keymgr")]
#[cfg(all(feature = "keymgr", feature = "experimental-api"))]
#[allow(clippy::option_option)]
fn deserialize_keystore_dir<'de, D>(deserializer: D) -> Result<Option<Option<CfgPath>>, D::Error>
where
@ -210,7 +213,7 @@ where
/// Deserialize the `keystore_dir` storage field.
///
/// NOTE: The first option is needed because of the builder, the second is the actual type of the field.
#[cfg(not(feature = "keymgr"))]
#[cfg(all(not(feature = "keymgr"), feature = "experimental-api"))]
#[allow(clippy::option_option)]
fn deserialize_keystore_dir<'de, D>(deserializer: D) -> Result<Option<Option<CfgPath>>, D::Error>
where
@ -228,6 +231,22 @@ where
}
}
/// Deserialize the `keystore_dir` storage field.
///
/// NOTE: The first option is needed because of the builder, the second is the actual type of the field.
#[cfg(not(feature = "experimental-api"))]
#[allow(clippy::option_option)]
fn deserialize_keystore_dir<'de, D>(deserializer: D) -> Result<Option<Option<CfgPath>>, D::Error>
where
D: serde::de::Deserializer<'de>,
{
use serde::de::Error as _;
Err(D::Error::custom(
"keystore not available unless the `experimental` feature is enabled".to_string(),
))
}
/// Return the default cache directory.
fn default_cache_dir() -> CfgPath {
CfgPath::new("${ARTI_CACHE}".to_owned())

View File

@ -16,8 +16,16 @@ default = ["expand-paths"]
full = ["expand-paths", "fs-mistrust/full", "tor-basic-utils/full", "tor-error/full"]
experimental = ["experimental-api"]
# Enable experimental APIs that are not yet officially supported.
#
# These APIs are not covered by semantic versioning. Using this
# feature voids your "semver warrantee".
experimental-api = ["__is_experimental"]
expand-paths = ["shellexpand", "directories"]
__is_experimental = []
[dependencies]
config = { version = "0.13", default-features = false, features = ["toml"] }
derive_builder = { version = "0.11.2", package = "derive_builder_fork_arti" }

View File

@ -387,6 +387,7 @@ impl TryFrom<ListenItemSerde> for ListenItem {
#[derive(Serialize, Deserialize, Debug)]
#[allow(clippy::exhaustive_enums)] // we will add variants very rarely if ever
#[serde(untagged, bound = "T: Serialize, for<'de2> T: Deserialize<'de2>")]
#[cfg(feature = "experimental-api")]
pub enum ItemOrBool<T>
where
T: std::fmt::Debug + Serialize,
@ -398,6 +399,7 @@ where
Bool(bool),
}
#[cfg(feature = "experimental-api")]
impl<T> Default for ItemOrBool<T>
where
T: std::fmt::Debug + Serialize,
@ -433,6 +435,7 @@ mod test {
#[serde(default)]
listen: Option<Listen>,
#[cfg(feature = "experimental-api")]
#[serde(default)]
enabled_or_string: ItemOrBool<String>,
}
@ -585,6 +588,7 @@ mod test {
}
#[test]
#[cfg(feature = "experimental-api")]
fn enabled_or_string() {
use ItemOrBool as IOB;