pub struct RecordArray {
pub records: Vec<Record>,
pub field_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
field_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 num_records(&self) -> usize
pub fn num_records(&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_values(
&self,
field_name: &str,
) -> Result<Vec<FieldValue>, ArrayError>
pub fn get_field_values( &self, field_name: &str, ) -> Result<Vec<FieldValue>, ArrayError>
Sourcepub fn get_field_as_f64(
&self,
field_name: &str,
) -> Result<Array<f64, Ix1>, ArrayError>
pub fn get_field_as_f64( &self, field_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 get_field_as_i64(
&self,
field_name: &str,
) -> Result<Array<i64, Ix1>, ArrayError>
pub fn get_field_as_i64( &self, field_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 get_field_as_string(
&self,
field_name: &str,
) -> Result<Vec<String>, ArrayError>
pub fn get_field_as_string( &self, field_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 set_field_value(
&mut self,
record_idx: usize,
field_name: &str,
value: FieldValue,
) -> Result<(), ArrayError>
pub fn set_field_value( &mut self, record_idx: usize, field_name: &str, 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 add_field(
&mut self,
field_name: &str,
values: Vec<FieldValue>,
) -> Result<(), ArrayError>
pub fn add_field( &mut self, field_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 remove_field(&mut self, field_name: &str) -> Result<(), ArrayError>
pub fn remove_field(&mut self, field_name: &str) -> Result<(), ArrayError>
Removes a field from all records
§Errors
Returns ArrayError::ValueError
if the field name is not found.
Sourcepub fn rename_field(
&mut self,
old_name: &str,
new_name: &str,
) -> Result<(), ArrayError>
pub fn rename_field( &mut self, old_name: &str, new_name: &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,
field_name: &str,
condition: F,
) -> Result<Self, ArrayError>
pub fn filter<F>( &self, field_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§const fn clone_from(&mut self, source: &Self)
const 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