Chris Morgan
›
Git
›
anymap
› commitdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
patch
|
inline
| side by side (from parent 1:
947a9a1
)
commit
grep
author
committer
pickaxe
?
search:
re
Make trait bounds more explicit.
author
Chris Morgan
<me@chrismorgan.info>
Fri, 7 Nov 2014 23:09:21 +0000
committer
Chris Morgan
<me@chrismorgan.info>
Fri, 7 Nov 2014 23:09:21 +0000
src/lib.rs
patch
|
blob
|
history
diff --git
a/src/lib.rs
b/src/lib.rs
index e7669130fd89b615c2472e07d714d9c8d3fd13a4..152a39715d2aaf7cea7a1b278ff4cd5625b75b45 100644
(file)
--- a/
src/lib.rs
+++ b/
src/lib.rs
@@
-122,28
+122,28
@@
impl AnyMap {
impl AnyMap {
/// Retrieve the value stored in the map for the type `T`, if it exists.
impl AnyMap {
/// Retrieve the value stored in the map for the type `T`, if it exists.
- pub fn find<T: 'static>(&self) -> Option<&T> {
+ pub fn find<T:
Any +
'static>(&self) -> Option<&T> {
self.data.find(&TypeId::of::<T>()).map(|any| unsafe { any.as_ref_unchecked::<T>() })
}
/// Retrieve a mutable reference to the value stored in the map for the type `T`, if it exists.
self.data.find(&TypeId::of::<T>()).map(|any| unsafe { any.as_ref_unchecked::<T>() })
}
/// Retrieve a mutable reference to the value stored in the map for the type `T`, if it exists.
- pub fn find_mut<T: 'static>(&mut self) -> Option<&mut T> {
+ pub fn find_mut<T:
Any +
'static>(&mut self) -> Option<&mut T> {
self.data.find_mut(&TypeId::of::<T>()).map(|any| unsafe { any.as_mut_unchecked::<T>() })
}
/// Set the value contained in the map for the type `T`.
/// This will override any previous value stored.
self.data.find_mut(&TypeId::of::<T>()).map(|any| unsafe { any.as_mut_unchecked::<T>() })
}
/// Set the value contained in the map for the type `T`.
/// This will override any previous value stored.
- pub fn insert<T: 'static>(&mut self, value: T) {
+ pub fn insert<T:
Any +
'static>(&mut self, value: T) {
self.data.insert(TypeId::of::<T>(), box value as Box<Any>);
}
/// Remove the value for the type `T` if it existed.
self.data.insert(TypeId::of::<T>(), box value as Box<Any>);
}
/// Remove the value for the type `T` if it existed.
- pub fn remove<T: 'static>(&mut self) {
+ pub fn remove<T:
Any +
'static>(&mut self) {
self.data.remove(&TypeId::of::<T>());
}
/// Does a value of type `T` exist?
self.data.remove(&TypeId::of::<T>());
}
/// Does a value of type `T` exist?
- pub fn contains<T: 'static>(&self) -> bool {
+ pub fn contains<T:
Any +
'static>(&self) -> bool {
self.data.contains_key(&TypeId::of::<T>())
}
self.data.contains_key(&TypeId::of::<T>())
}