From 1376c5a617be5c25655d0d7cb63e3beaa5a6e026 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:20:39 +0200 Subject: Merging upstream version 1.70.0+dfsg1. Signed-off-by: Daniel Baumann --- vendor/clap_builder/src/util/id.rs | 164 +++++++++++++++++++++++++++++++++++++ 1 file changed, 164 insertions(+) create mode 100644 vendor/clap_builder/src/util/id.rs (limited to 'vendor/clap_builder/src/util/id.rs') diff --git a/vendor/clap_builder/src/util/id.rs b/vendor/clap_builder/src/util/id.rs new file mode 100644 index 000000000..710d2ea7d --- /dev/null +++ b/vendor/clap_builder/src/util/id.rs @@ -0,0 +1,164 @@ +use crate::builder::Str; + +/// [`Arg`][crate::Arg] or [`ArgGroup`][crate::ArgGroup] identifier +/// +/// This is used for accessing the value in [`ArgMatches`][crate::ArgMatches] or defining +/// relationships between `Arg`s and `ArgGroup`s with functions like +/// [`Arg::conflicts_with`][crate::Arg::conflicts_with]. +#[derive(Default, Clone, Eq, PartialEq, PartialOrd, Ord, Hash)] +pub struct Id(Str); + +impl Id { + pub(crate) const HELP: &'static str = "help"; + pub(crate) const VERSION: &'static str = "version"; + pub(crate) const EXTERNAL: &'static str = ""; + + pub(crate) fn from_static_ref(name: &'static str) -> Self { + Self(Str::from_static_ref(name)) + } + + /// Get the raw string of the `Id` + pub fn as_str(&self) -> &str { + self.0.as_str() + } + + pub(crate) fn as_internal_str(&self) -> &Str { + &self.0 + } +} + +impl From<&'_ Id> for Id { + fn from(id: &'_ Id) -> Self { + id.clone() + } +} + +impl From for Id { + fn from(name: Str) -> Self { + Self(name) + } +} + +impl From<&'_ Str> for Id { + fn from(name: &'_ Str) -> Self { + Self(name.into()) + } +} + +#[cfg(feature = "string")] +impl From for Id { + fn from(name: std::string::String) -> Self { + Self(name.into()) + } +} + +#[cfg(feature = "string")] +impl From<&'_ std::string::String> for Id { + fn from(name: &'_ std::string::String) -> Self { + Self(name.into()) + } +} + +impl From<&'static str> for Id { + fn from(name: &'static str) -> Self { + Self(name.into()) + } +} + +impl From<&'_ &'static str> for Id { + fn from(name: &'_ &'static str) -> Self { + Self(name.into()) + } +} + +impl From for Str { + fn from(name: Id) -> Self { + name.0 + } +} + +impl From for String { + fn from(name: Id) -> Self { + Str::from(name).into() + } +} + +impl std::fmt::Display for Id { + #[inline] + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.as_str(), f) + } +} + +impl std::fmt::Debug for Id { + #[inline] + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Debug::fmt(self.as_str(), f) + } +} + +impl AsRef for Id { + #[inline] + fn as_ref(&self) -> &str { + self.as_str() + } +} + +impl std::borrow::Borrow for Id { + #[inline] + fn borrow(&self) -> &str { + self.as_str() + } +} + +impl PartialEq for Id { + #[inline] + fn eq(&self, other: &str) -> bool { + PartialEq::eq(self.as_str(), other) + } +} +impl PartialEq for str { + #[inline] + fn eq(&self, other: &Id) -> bool { + PartialEq::eq(self, other.as_str()) + } +} + +impl PartialEq<&'_ str> for Id { + #[inline] + fn eq(&self, other: &&str) -> bool { + PartialEq::eq(self.as_str(), *other) + } +} +impl PartialEq for &'_ str { + #[inline] + fn eq(&self, other: &Id) -> bool { + PartialEq::eq(*self, other.as_str()) + } +} + +impl PartialEq for Id { + #[inline] + fn eq(&self, other: &Str) -> bool { + PartialEq::eq(self.as_str(), other.as_str()) + } +} +impl PartialEq for Str { + #[inline] + fn eq(&self, other: &Id) -> bool { + PartialEq::eq(self.as_str(), other.as_str()) + } +} + +impl PartialEq for Id { + #[inline] + fn eq(&self, other: &std::string::String) -> bool { + PartialEq::eq(self.as_str(), other.as_str()) + } +} +impl PartialEq for std::string::String { + #[inline] + fn eq(&self, other: &Id) -> bool { + PartialEq::eq(other, self) + } +} -- cgit v1.2.3