Skip to content

Commit

Permalink
Merge pull request #4873 from Molkars/master
Browse files Browse the repository at this point in the history
impl Eq<std::any::TypeId> for clap_builder::util::AnyValueId
  • Loading branch information
epage committed May 2, 2023
2 parents be88567 + 3750774 commit a2131ae
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions clap_builder/src/util/any_value.rs
Expand Up @@ -69,6 +69,12 @@ impl PartialOrd for AnyValueId {
}
}

impl PartialEq<std::any::TypeId> for AnyValueId {
fn eq(&self, other: &std::any::TypeId) -> bool {
self.type_id == *other
}
}

impl Ord for AnyValueId {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.type_id.cmp(&other.type_id)
Expand Down Expand Up @@ -109,4 +115,13 @@ mod test {

assert_eq!(format!("{:?}", AnyValue::new(5)), "AnyValue { inner: i32 }");
}

#[test]
fn eq_to_type_id() {
use super::*;

let any_value_id = AnyValueId::of::<i32>();
let type_id = std::any::TypeId::of::<i32>();
assert_eq!(any_value_id, type_id);
}
}

0 comments on commit a2131ae

Please sign in to comment.