From 96716661f9dc94a14bb9174ab124c15611373e60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81d=C3=A1m=20Lippai?= Date: Sat, 29 May 2021 13:02:21 +0200 Subject: [PATCH] Add doctest for ArrayBuilder (#367) --- arrow/src/array/builder.rs | 51 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/arrow/src/array/builder.rs b/arrow/src/array/builder.rs index 458831a77711..a9e7fe24a830 100644 --- a/arrow/src/array/builder.rs +++ b/arrow/src/array/builder.rs @@ -383,6 +383,57 @@ impl From for Buffer { } /// Trait for dealing with different array builders at runtime +/// +/// # Example +/// +/// ``` +/// # use arrow::{ +/// # array::{ArrayBuilder, ArrayRef, Float64Builder, Int64Builder, StringArray, StringBuilder}, +/// # error::ArrowError, +/// # }; +/// # fn main() -> std::result::Result<(), ArrowError> { +/// // Create +/// let mut data_builders: Vec> = vec![ +/// Box::new(Float64Builder::new(1024)), +/// Box::new(Int64Builder::new(1024)), +/// Box::new(StringBuilder::new(1024)), +/// ]; +/// +/// // Fill +/// data_builders[0] +/// .as_any_mut() +/// .downcast_mut::() +/// .unwrap() +/// .append_value(3.14)?; +/// data_builders[1] +/// .as_any_mut() +/// .downcast_mut::() +/// .unwrap() +/// .append_value(-1)?; +/// data_builders[2] +/// .as_any_mut() +/// .downcast_mut::() +/// .unwrap() +/// .append_value("🍎")?; +/// +/// // Finish +/// let array_refs: Vec = data_builders +/// .iter_mut() +/// .map(|builder| builder.finish()) +/// .collect(); +/// assert_eq!(array_refs[0].len(), 1); +/// assert_eq!(array_refs[1].is_null(0), false); +/// assert_eq!( +/// array_refs[2] +/// .as_any() +/// .downcast_ref::() +/// .unwrap() +/// .value(0), +/// "🍎" +/// ); +/// # Ok(()) +/// # } +/// ``` pub trait ArrayBuilder: Any + Send { /// Returns the number of array slots in the builder fn len(&self) -> usize;