Skip to content

Commit

Permalink
impl Eq<std::any::TypeId> for clap_builder::util::AnyValueId
Browse files Browse the repository at this point in the history
  • Loading branch information
Molkars committed May 1, 2023
1 parent fa57ed3 commit 3750774
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions clap_builder/src/util/any_value.rs
Original file line number Diff line number Diff line change
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 3750774

Please sign in to comment.