pub struct RecordArray {
pub records: Vec<Record>,
pub names: Vec<String>,
pub field_titles: HashMap<String, String>,
/* private fields */
}
Expand description
A structured array with named fields
Fields§
§records: Vec<Record>
The array of records
names: Vec<String>
The names of the fields (columns)
field_titles: HashMap<String, String>
Optional titles (aliases) for fields
Implementations§
Source§impl RecordArray
impl RecordArray
Sourcepub fn new(records: Vec<Record>) -> Result<Self, ArrayError>
pub fn new(records: Vec<Record>) -> Result<Self, ArrayError>
Create a new RecordArray
from a vector of records
§Errors
Returns ArrayError::ValueError
if records are empty or have inconsistent field structures.
Sourcepub fn with_titles(
records: Vec<Record>,
titles: HashMap<String, String>,
) -> Result<Self, ArrayError>
pub fn with_titles( records: Vec<Record>, titles: HashMap<String, String>, ) -> Result<Self, ArrayError>
Create a new RecordArray
with custom field titles
§Errors
Returns ArrayError::ValueError
if records are invalid or titles reference non-existent fields.
Sourcepub const fn set_allow_field_attributes(&mut self, allow: bool)
pub const fn set_allow_field_attributes(&mut self, allow: bool)
Enable or disable attribute-style field access
Sourcepub const fn allow_field_attributes(&self) -> bool
pub const fn allow_field_attributes(&self) -> bool
Get whether attribute-style field access is allowed
Sourcepub fn field_values(&self, name: &str) -> Result<Vec<FieldValue>, ArrayError>
pub fn field_values(&self, name: &str) -> Result<Vec<FieldValue>, ArrayError>
Get all values for a specific field across all records
Sourcepub fn numrecords(&self) -> usize
pub fn numrecords(&self) -> usize
Get the number of records
Sourcepub fn get_record(&self, index: usize) -> Option<&Record>
pub fn get_record(&self, index: usize) -> Option<&Record>
Get a reference to a record by index
Sourcepub fn get_record_mut(&mut self, index: usize) -> Option<&mut Record>
pub fn get_record_mut(&mut self, index: usize) -> Option<&mut Record>
Get a mutable reference to a record by index
Sourcepub fn get_field(&self, name: &str) -> Result<Vec<FieldValue>, ArrayError>
pub fn get_field(&self, name: &str) -> Result<Vec<FieldValue>, ArrayError>
Sourcepub fn field_as_f64_array(
&self,
name: &str,
) -> Result<Array<f64, Ix1>, ArrayError>
pub fn field_as_f64_array( &self, name: &str, ) -> Result<Array<f64, Ix1>, ArrayError>
Get a field as an array of f64 values
§Errors
Returns ArrayError::ValueError
if the field name is not found.
Sourcepub fn field_as_i64_array(
&self,
name: &str,
) -> Result<Array<i64, Ix1>, ArrayError>
pub fn field_as_i64_array( &self, name: &str, ) -> Result<Array<i64, Ix1>, ArrayError>
Get a field as an array of i64 values
§Errors
Returns ArrayError::ValueError
if the field name is not found or contains non-convertible types.
Sourcepub fn name_4(&self, name: &str) -> Result<Vec<String>, ArrayError>
pub fn name_4(&self, name: &str) -> Result<Vec<String>, ArrayError>
Get a field as an array of String values
§Errors
Returns ArrayError::ValueError
if the field name is not found.
Sourcepub fn get_field_by_title(
&self,
title: &str,
) -> Result<Vec<FieldValue>, ArrayError>
pub fn get_field_by_title( &self, title: &str, ) -> Result<Vec<FieldValue>, ArrayError>
Get a field by its title (alias) rather than its name
§Errors
Returns ArrayError::ValueError
if the title is not found.
Sourcepub fn name_5(
&mut self,
name: &str,
record_idx: usize,
value: FieldValue,
) -> Result<(), ArrayError>
pub fn name_5( &mut self, name: &str, record_idx: usize, value: FieldValue, ) -> Result<(), ArrayError>
Set a field value for a record
§Errors
Returns ArrayError::ValueError
if the field name is not found or record index is out of bounds.
Sourcepub fn name_6(
&mut self,
name: &str,
values: Vec<FieldValue>,
) -> Result<(), ArrayError>
pub fn name_6( &mut self, name: &str, values: Vec<FieldValue>, ) -> Result<(), ArrayError>
Adds a new field to all records
§Errors
Returns ArrayError::ValueError
if the field already exists or the number of values doesn’t match the number of records.
Sourcepub fn name_7(&mut self, name: &str) -> Result<(), ArrayError>
pub fn name_7(&mut self, name: &str) -> Result<(), ArrayError>
Removes a field from all records
§Errors
Returns ArrayError::ValueError
if the field name is not found.
Sourcepub fn name_8(
&mut self,
old_name: &str,
newname: &str,
) -> Result<(), ArrayError>
pub fn name_8( &mut self, old_name: &str, newname: &str, ) -> Result<(), ArrayError>
Rename a field
§Errors
Returns ArrayError::ValueError
if old field is not found or new field already exists.
Sourcepub fn view(&self, indices: &[usize]) -> Result<Self, ArrayError>
pub fn view(&self, indices: &[usize]) -> Result<Self, ArrayError>
Create a view of the record array with a subset of records
§Errors
Returns ArrayError::ValueError
if any index is out of bounds.
Sourcepub fn filter<F>(&self, name: &str, condition: F) -> Result<Self, ArrayError>
pub fn filter<F>(&self, name: &str, condition: F) -> Result<Self, ArrayError>
Filter the record array by a condition on a field
§Errors
Returns ArrayError::ValueError
if the field name is not found.
Sourcepub fn merge(&self, other: &Self) -> Result<Self, ArrayError>
pub fn merge(&self, other: &Self) -> Result<Self, ArrayError>
Merge two record arrays with compatible fields
§Errors
Returns ArrayError::ValueError
if the arrays have incompatible field structures.
Trait Implementations§
Source§impl Clone for RecordArray
impl Clone for RecordArray
Source§fn clone(&self) -> RecordArray
fn clone(&self) -> RecordArray
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for RecordArray
impl Debug for RecordArray
Auto Trait Implementations§
impl Freeze for RecordArray
impl RefUnwindSafe for RecordArray
impl Send for RecordArray
impl Sync for RecordArray
impl Unpin for RecordArray
impl UnwindSafe for RecordArray
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more