-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Remove redundant check in Reflect::downcast
method
#5120
Comments
From @PROMETHIA-27. |
Hi. I've got this! |
I've attempted to take the prescribed approach to resolve this. I would prefer to not create a copy, however, being new to Rust I'm not sure how to avoid this. I considered Am I missing something here? 😄 pub fn downcast<T: Reflect>(self: Box<dyn Reflect>) -> Result<Box<T>, Box<dyn Reflect>> {
let copy_of_self = self.clone_value();
match self.into_any().downcast::<T>() {
Ok(downcasted) => Ok(downcasted),
Err(_) => Err(copy_of_self),
}
} |
This won't work. We can use impl<T: Reflect> GetTypeId for Reflect {
fn get_type_id(&self) -> TypeId {
TypeId::of::<T>()
}
} and then using that and a manual comparison instead of Overall I don't think this issue is actually a good first issue, and I think it's a lot of effort for a microoptimization. |
Thanks for the response. Learned a few things. I'll take myself out of the running for this issue 👍 |
When attempting to downcast to a type, we check if the type is correct here. However, the
Any::downcast
method used inside this call does this anyways.We should remove this check, and then match on the returned
Result
from theAny
version.Spotted by @cart in #5010 here.
The text was updated successfully, but these errors were encountered: