move any bound to trait instead of implementation
This commit is contained in:
1 parent
e4a7e4582b
commit
0ac02cc893
1 file changed
+4
-9
@@ -394,7 +394,7 @@ impl AnyValueRc {
|
|||||||
|
|
||||||
/// Returns a reference to the inner value.
|
/// Returns a reference to the inner value.
|
||||||
pub fn downcast_ref<T: Any + PartialEq>(&self) -> Option<&T> {
|
pub fn downcast_ref<T: Any + PartialEq>(&self) -> Option<&T> {
|
||||||
if self.0.our_typeid() == TypeId::of::<T>() {
|
if self.0.type_id() == TypeId::of::<T>() {
|
||||||
Some(unsafe { self.downcast_ref_unchecked() })
|
Some(unsafe { self.downcast_ref_unchecked() })
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
@@ -403,7 +403,7 @@ impl AnyValueRc {
|
|||||||
|
|
||||||
/// Checks if the inner value is of type `T`.
|
/// Checks if the inner value is of type `T`.
|
||||||
pub fn is<T: Any + PartialEq>(&self) -> bool {
|
pub fn is<T: Any + PartialEq>(&self) -> bool {
|
||||||
self.0.our_typeid() == TypeId::of::<T>()
|
self.0.type_id() == TypeId::of::<T>()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -468,23 +468,18 @@ impl<'a> PartialEq for AttributeValue<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub trait AnyValue {
|
pub trait AnyValue: Any {
|
||||||
fn any_cmp(&self, other: &dyn AnyValue) -> bool;
|
fn any_cmp(&self, other: &dyn AnyValue) -> bool;
|
||||||
fn our_typeid(&self) -> TypeId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: PartialEq + Any> AnyValue for T {
|
impl<T: PartialEq + Any> AnyValue for T {
|
||||||
fn any_cmp(&self, other: &dyn AnyValue) -> bool {
|
fn any_cmp(&self, other: &dyn AnyValue) -> bool {
|
||||||
if self.type_id() != other.our_typeid() {
|
if self.type_id() != other.type_id() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
self == unsafe { &*(other as *const _ as *const T) }
|
self == unsafe { &*(other as *const _ as *const T) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn our_typeid(&self) -> TypeId {
|
|
||||||
self.type_id()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
|
|||||||
Reference in new issue
Block a user