-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Add TypeIdMapExt trait to make TypeIdMap operations more ergonomic #19683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@@ -38,6 +38,78 @@ impl<K: Hash + Eq + PartialEq + Clone, V> PreHashMapExt<K, V> for PreHashMap<K, | |||
/// Iteration order only depends on the order of insertions and deletions. | |||
pub type TypeIdMap<V> = HashMap<TypeId, V, NoOpHash>; | |||
|
|||
/// Extension trait to make use of [`TypeIdMap`] more ergonomic. | |||
/// | |||
/// # Examples |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this example is a bit too explicit 🤔 I would probably remove it, all methods are extremely simple.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it’s worth having a simple example of what this is doing, but maybe mot one that uses all of the new functions - I’ll cut this down after adding entry
and entry_mut
.
/// map.remove_type::<MyType>(); | ||
/// assert_eq!(map.len(), 0); | ||
/// ``` | ||
pub trait TypeIdMapExt<V> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add entry
/entry_mut
as well?
Objective
Fix #19642 by enabling e.g.
in place of
Solution
Add an extension trait
TypeIdMapExt
withinsert_type
,get_type
,get_type_mut
andremove_type
counterparts forinsert
,get
,get_mut
andremove
.Testing
Doc test.