timsaucer opened a new issue, #21572: URL: https://github.com/apache/datafusion/issues/21572
### Is your feature request related to a problem or challenge? Starting in https://github.com/apache/datafusion/pull/20812 I have opened PRs to remove the `as_any` function in our trait definitions. Since we have upgrade our MSRV to >1.86 we can take advantage of trait upcasting to get the same result with less boilerplate code. ### Describe the solution you'd like For all trait definitions, remove the `as_any()` function. Add a trait object implementation to give the downcasting for easier usage. Here is an example for `TableProvider` ``` impl dyn TableProvider { /// Returns `true` if the table provider is of type `T`. /// /// Prefer this over `downcast_ref::<T>().is_some()`. Works correctly when /// called on `Arc<dyn TableProvider>` via auto-deref. pub fn is<T: TableProvider>(&self) -> bool { (self as &dyn Any).is::<T>() } /// Attempts to downcast this table provider to a concrete type `T`, /// returning `None` if the provider is not of that type. /// /// Works correctly when called on `Arc<dyn TableProvider>` via auto-deref, /// unlike `(&arc as &dyn Any).downcast_ref::<T>()` which would attempt to /// downcast the `Arc` itself. pub fn downcast_ref<T: TableProvider>(&self) -> Option<&T> { (self as &dyn Any).downcast_ref() } } ``` ### Describe alternatives you've considered We could leave code as is, but this is removing >1000 of lines of boilerplate code across the PRs. ### Additional context _No response_ -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
