Skip to content

Commit

Permalink
Improve doc strings for as_primtive_array
Browse files Browse the repository at this point in the history
  • Loading branch information
alamb committed Jul 15, 2022
1 parent a7181dd commit fd39d41
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion arrow/src/array/cast.rs
Expand Up @@ -20,7 +20,19 @@
use crate::array::*;
use crate::datatypes::*;

/// Force downcast ArrayRef to PrimitiveArray<T>
/// Force downcast of an [`Array`], such as an [`ArrayRef`], to
/// [`PrimitiveArray<T>`], panic'ing on failure:
///
/// ```
/// # use arrow::array::*;
/// # use arrow::datatypes::*;
/// # let arr: ArrayRef = std::sync::Arc::new(Int32Array::from(vec![Some(1)]));
/// // Downcast an `ArrayRef` to Int32Array / PrimiveArray<Int32>:
/// let primitive_array: &Int32Array = as_primitive_array(&arr);
///
/// // Equivalently:
/// let primitive_array = as_primitive_array::<Int32Type>(&arr);
/// ```
pub fn as_primitive_array<T>(arr: &dyn Array) -> &PrimitiveArray<T>
where
T: ArrowPrimitiveType,
Expand Down

0 comments on commit fd39d41

Please sign in to comment.