tustvold commented on code in PR #2902:
URL: https://github.com/apache/arrow-rs/pull/2902#discussion_r1003629274
##########
arrow-array/src/array/mod.rs:
##########
@@ -88,6 +88,31 @@ pub trait Array: std::fmt::Debug + Send + Sync {
/// ```
fn as_any(&self) -> &dyn Any;
+ /// Returns the array as [`Any`](std::any::Any) wrapped into an [`Arc`] so
that it can be
+ /// downcasted to a specific implementation without the need for an
unsized reference. This is helpful if you want
+ /// to return a concrete array type.
+ ///
+ /// Note that this conversion may not be possible for all types due to the
`'static` constraint.
+ ///
+ /// # Example:
+ ///
+ /// ```
+ /// # use std::sync::Arc;
+ /// # use arrow_array::{Int32Array, RecordBatch};
+ /// # use arrow_schema::{Schema, Field, DataType, ArrowError};
+ ///
+ /// let id = Int32Array::from(vec![1, 2, 3, 4, 5]);
+ /// let batch = RecordBatch::try_new(
+ /// Arc::new(Schema::new(vec![Field::new("id", DataType::Int32,
false)])),
+ /// vec![Arc::new(id)]
+ /// ).unwrap();
+ ///
+ /// let int32array = Arc::downcast::<Int32Array>(
+ /// Arc::clone(batch.column(0)).as_any_arc().expect("Failed to create
static Arc")
+ /// ).expect("Failed to downcast");
Review Comment:
Yes, the nature of the way that the downcasting works means that Array is
effectively sealed as there would be no use to implementing it
--
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]