Create a new [`UnionFields`] from a collection of fields with automatically assigned type IDs starting from 0. The type IDs are assigned in increasing order: 0, 1, 2, 3, etc. This is the non-panicking version of [`UnionFields::from_fields`]. See # Errors Returns an error if the number of fields exceeds 127 (the maximum value fo
(fields: F)
| 515 | /// assert!(result.is_err()); |
| 516 | /// ``` |
| 517 | pub fn try_from_fields<F>(fields: F) -> Result<Self, ArrowError> |
| 518 | where |
| 519 | F: IntoIterator, |
| 520 | F::Item: Into<FieldRef>, |
| 521 | { |
| 522 | let mut out = Vec::with_capacity(i8::MAX as usize + 1); |
| 523 | |
| 524 | for (i, field) in fields.into_iter().enumerate() { |
| 525 | let id = i8::try_from(i).map_err(|_| { |
| 526 | ArrowError::InvalidArgumentError( |
| 527 | "UnionFields cannot contain more than 128 fields".into(), |
| 528 | ) |
| 529 | })?; |
| 530 | |
| 531 | out.push((id, field.into())); |
| 532 | } |
| 533 | |
| 534 | Ok(Self(out.into())) |
| 535 | } |
| 536 | |
| 537 | /// Return size of this instance in bytes. |
| 538 | pub fn size(&self) -> usize { |