alamb commented on issue #1128:
URL: https://github.com/apache/arrow-rs/issues/1128#issuecomment-1005615737
I was able to use the borrow idea like this, but it still requires two
generic arguments to `as_primitive_array` (and thus requires many code level
changes which I am trying to avoid)
```rust
/// Force downcast ArrayRef to PrimitiveArray<T>
pub fn as_primitive_array<F, T>(arr: &F) -> &PrimitiveArray<T>
where
F: Borrow<dyn Array> + ?Sized,
T: ArrowPrimitiveType,
{
arr.borrow()
.as_any()
.downcast_ref::<PrimitiveArray<T>>()
.expect("Unable to downcast to primitive array")
}
```
I also tried using an `impl`
```rust
/// Force downcast ArrayRef to PrimitiveArray<T>
pub fn as_primitive_array<T>(arr: &(impl Borrow<dyn Array> + ?Sized)) ->
&PrimitiveArray<T>
where
T: ArrowPrimitiveType,
{
arr.borrow()
.as_any()
.downcast_ref::<PrimitiveArray<T>>()
.expect("Unable to downcast to primitive array")
}
```
which seemed to get me what I wanted, but then rust seemed to be unhappy
about mixing explicit and implicit generics:
```
error[E0632]: cannot provide explicit generic arguments when `impl Trait` is
used in argument position
--> arrow/src/compute/kernels/comparison.rs:904:49
|
904 | let left = as_primitive_array::<Int8Type>($LEFT);
| ^^^^^^^^ explicit
generic argument not allowed
...
1103 | | DataType::UInt64 => {dyn_compare_scalar!(&left, right,
key_type, eq_scalar)}
|
------------------------------------------------------ in this macro invocation
```
--
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]