You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "timsaucer (via GitHub)" <gi...@apache.org> on 2026/04/12 16:39:32 UTC
[I] Remove `as_any` from trait definitions [datafusion]
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: github-unsubscribe@datafusion.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [I] Remove `as_any` from trait definitions [datafusion]
Posted by "LorrensP-2158466 (via GitHub)" <gi...@apache.org>.
LorrensP-2158466 commented on issue #21572:
URL: https://github.com/apache/datafusion/issues/21572#issuecomment-5524683961
Hi @timsaucer, is it okey if I do some of these? It would be useful in my own projects :)
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org