tustvold edited a comment on issue #1128: URL: https://github.com/apache/arrow-rs/issues/1128#issuecomment-1004081792
Perhaps `fn as_primitive_array<T>(arr: &impl AsRef<dyn Array>) -> &PrimitiveArray<T>`? If you explicitly specify the lifetimes it is easier to see what the compiler is complaining about `fn as_primitive_array<'a, T>(arr: &'a impl AsRef<dyn Array>) -> &'a PrimitiveArray<T>` In the version without an argument passed by reference there is nothing to automatically infer the return lifetime from, and so the compiler is asking you to specify a named lifetime parameter. **Edit**: This doesn't work for &dyn Foo... Will think further :thinking: **Edit edit**: [This](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=98ebefb3a35cd911c9a355c136cb14af) works but is kinda gross. You need to use `Borrow` instead of `AsRef` as we need the blanket [impl](https://doc.rust-lang.org/std/borrow/trait.Borrow.html#impl-Borrow%3CT%3E) so we don't get an error like `the trait 'AsRef<(dyn Foo + 'static)>' is not implemented for 'dyn Foo'`. This does raise the question though, if `as_primitive_array` doesn't need to be passed a reference to an `Arc` why it takes one at all... The generics will preserve backwards compatibility but at the cost of potentially greater confusion down the line... -- 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]
