summaryrefslogtreecommitdiff
path: root/crates/tor-config
diff options
context:
space:
mode:
Diffstat (limited to 'crates/tor-config')
-rw-r--r--crates/tor-config/Cargo.toml1
-rw-r--r--crates/tor-config/src/misc.rs21
2 files changed, 22 insertions, 0 deletions
diff --git a/crates/tor-config/Cargo.toml b/crates/tor-config/Cargo.toml
index 7511573aa..a13c1a40e 100644
--- a/crates/tor-config/Cargo.toml
+++ b/crates/tor-config/Cargo.toml
@@ -65,6 +65,7 @@ void = "1"
serde_json = "1.0.50"
tempfile = "3"
test-temp-dir = { version = "0.3.5", path = "../test-temp-dir" }
+tor-basic-utils = { path = "../tor-basic-utils", version = "0.32.0", features = ["serde"] }
tor-rtcompat = { path = "../tor-rtcompat", version = "0.32.0", features = ["tokio", "native-tls"] }
tracing-test = "0.2.4"
diff --git a/crates/tor-config/src/misc.rs b/crates/tor-config/src/misc.rs
index 5b0a080ea..e26482837 100644
--- a/crates/tor-config/src/misc.rs
+++ b/crates/tor-config/src/misc.rs
@@ -242,6 +242,24 @@ impl<T: NotAutoValue> ExplicitOrAuto<T> {
ExplicitOrAuto::Explicit(v) => Some(v),
}
}
+
+ /// Maps an `ExplicitOrAuto<T>` to an `ExplicitOrAuto<U>` by applying a function to a contained
+ /// value.
+ pub fn map<U: NotAutoValue>(self, f: impl FnOnce(T) -> U) -> ExplicitOrAuto<U> {
+ match self {
+ Self::Auto => ExplicitOrAuto::Auto,
+ Self::Explicit(x) => ExplicitOrAuto::Explicit(f(x)),
+ }
+ }
+}
+
+impl<T> From<T> for ExplicitOrAuto<T>
+where
+ T: NotAutoValue,
+{
+ fn from(x: T) -> Self {
+ Self::Explicit(x)
+ }
}
/// A marker trait for types that do not serialize to the same value as [`ExplicitOrAuto::Auto`].
@@ -268,6 +286,9 @@ impl_not_auto_value_for_types!(
bool
);
+use tor_basic_utils::ByteQty;
+impl_not_auto_value!(ByteQty);
+
// TODO implement `NotAutoValue` for other types too
/// Padding enablement - rough amount of padding requested