summaryrefslogtreecommitdiff
path: root/crates/tor-config/src/misc.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/tor-config/src/misc.rs')
-rw-r--r--crates/tor-config/src/misc.rs21
1 files changed, 21 insertions, 0 deletions
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