/// Clearable builder value /// /// This allows a builder function to both accept any value that can [`Into::into`] `T` (like /// `&str` into `OsStr`) as well as `None` to reset it to the default. This is needed to /// workaround a limitation where you can't have a function argument that is `impl Into<Option<T>>` /// where `T` is `impl Into<S>` accept `None` as its type is ambiguous. /// /// # Example /// /// ```rust /// # use clap_builder as clap; /// # use clap::Command; /// # use clap::Arg; /// fn common() -> Command { /// Command::new("cli") /// .arg(Arg::new("input").short('i').long("input")) /// } /// let mut command = common(); /// command.mut_arg("input", |arg| arg.short(None)); /// ``` #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pubenum Resettable<T> { /// Overwrite builder value
Value(T), /// Reset builder value
Reset,
}
impl<T> From<Option<T>> for Resettable<T> { fn from(other: Option<T>) -> Self { match other {
Some(inner) => Self::Value(inner),
None => Self::Reset,
}
}
}
/// Convert to the intended resettable type pubtrait IntoResettable<T> { /// Convert to the intended resettable type fn into_resettable(self) -> Resettable<T>;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.