From c52b3e721aee620ae45d6623799cc89222d7a015 Mon Sep 17 00:00:00 2001 From: Jorge Leitao Date: Wed, 29 Jun 2022 20:12:17 -0700 Subject: [PATCH] Improved example (#1131) --- examples/cow.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/examples/cow.rs b/examples/cow.rs index 5548f453a16..65e3920727c 100644 --- a/examples/cow.rs +++ b/examples/cow.rs @@ -19,4 +19,20 @@ fn main() { // confirm that it gives the right result :) assert_eq!(array, &PrimitiveArray::from_vec(vec![10i32, 20])); + + // alternatively, you can use `get_mut_values`. Unwrap works because it is single owned + let values = array.get_mut_values().unwrap(); + values[0] = 0; + + assert_eq!(array, &PrimitiveArray::from_vec(vec![0, 20])); + + // you can also modify the validity: + array.set_validity(Some([true, false].into())); + array.apply_validity(|bitmap| { + let mut mut_bitmap = bitmap.into_mut().right().unwrap(); + mut_bitmap.set(1, true); + mut_bitmap.into() + }); + + assert_eq!(array, &PrimitiveArray::from_vec(vec![0, 20])); }