Returns a zero-copy slice of this array with the indicated offset and length.
(&self, offset: usize, length: usize)
| 329 | |
| 330 | /// Returns a zero-copy slice of this array with the indicated offset and length. |
| 331 | pub fn slice(&self, offset: usize, length: usize) -> Self { |
| 332 | let (offsets, fields) = match self.offsets.as_ref() { |
| 333 | // If dense union, slice offsets |
| 334 | Some(offsets) => (Some(offsets.slice(offset, length)), self.fields.clone()), |
| 335 | // Otherwise need to slice sparse children |
| 336 | None => { |
| 337 | let fields = self |
| 338 | .fields |
| 339 | .iter() |
| 340 | .map(|x| x.as_ref().map(|x| x.slice(offset, length))) |
| 341 | .collect(); |
| 342 | (None, fields) |
| 343 | } |
| 344 | }; |
| 345 | |
| 346 | Self { |
| 347 | data_type: self.data_type.clone(), |
| 348 | type_ids: self.type_ids.slice(offset, length), |
| 349 | offsets, |
| 350 | fields, |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | /// Deconstruct this array into its constituent parts |
| 355 | /// |