scovich commented on PR #12318: URL: https://github.com/apache/arrow-rs/pull/12318#issuecomment-7117077469
> > > I didn't explore the possibility of `Array::slice` as a starting point before > > > > > > A few observation as I dust off memories: > > > > 1. [No way to downcast Arc to Arc<T: Array> #8794](https://github.com/apache/arrow-rs/issues/8794) is specifically trying to recover an `Arc<T: Array>` from `Arc<dyn Array>` _without cloning_ (a downcast of sorts), which is a different problem than `Array::to_arc` would solve. > > 2. If we're ok with cloning, then we don't even need to start from `Array::slice`. Every in-tree `T: Array` is also `T: Clone`, so `to_arc` for all the concrete array types is just `Arc::new(self.clone())`. If we wanted a provided `to_arc` so the new method isn't a breaking change, that would have to delegate to `Array::slice` because we don't require `Array: Clone`. > > I was mostly thinking that the key usecase is a function that takes `&dyn Array` or `&dyn Datum` as input but whose signature must return an `Arc<&dyn Array>` (aka ArrayRef) as is the case here. Ideally that process would only require a single Arc increment rather than `slice` or cloneing Yeah, sadly I don't think there's any safe rust way of doing that. Once `Arc<T>::as_ref` has produced a `&T`, there's no going back. Even if we used unsafe code, miri would freak out because the memory region tracking would be off. And all that ignores the glaring issue that it's completely wild west if the user provided an actual `&T` that wasn't backed by an `Arc` in the first place. The closest we could do is have `impl Array for Arc<dyn Array>` return `Arc::clone(self)`. -- 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]
