pub trait Record<'a>:
Debug
+ Send
+ Sync
+ TryFrom<IndexMap<String, DmapField>, Error = DmapError> {
Show 25 methods
// Required methods
fn new(fields: &mut IndexMap<String, DmapField>) -> Result<Self, DmapError>
where Self: Sized;
fn inner(self) -> IndexMap<String, DmapField>;
fn get(&self, key: &str) -> Option<&DmapField>;
fn keys(&self) -> Vec<&String>;
fn is_metadata_field(name: &str) -> bool;
fn to_bytes(&self) -> Result<Vec<u8>, DmapError>;
// Provided methods
fn read_nth_records(
dmap_data: impl Read,
indices: &[i32],
) -> Result<Vec<Self>, DmapError>
where Self: Sized + Send { ... }
fn read_nth_records_lax(
dmap_data: impl Read,
indices: &[i32],
) -> Result<(Vec<Self>, Option<usize>), DmapError>
where Self: Sized + Send { ... }
fn read_records(dmap_data: impl Read) -> Result<Vec<Self>, DmapError>
where Self: Sized + Send { ... }
fn read_metadata(
dmap_data: impl Read,
) -> Result<Vec<IndexMap<String, DmapField>>, DmapError>
where Self: Sized + Send { ... }
fn read_metadata_by_indices(
dmap_data: impl Read,
indices: &[i32],
) -> Result<Vec<IndexMap<String, DmapField>>, DmapError>
where Self: Sized + Send { ... }
fn read_records_lax(
dmap_data: impl Read,
) -> Result<(Vec<Self>, Option<usize>), DmapError>
where Self: Sized + Send { ... }
fn read_file<P: AsRef<Path>>(infile: P) -> Result<Vec<Self>, DmapError>
where Self: Sized + Send { ... }
fn read_file_lax<P: AsRef<Path>>(
infile: P,
) -> Result<(Vec<Self>, Option<usize>), DmapError>
where Self: Sized + Send { ... }
fn read_file_by_indices<P: AsRef<Path>>(
infile: P,
indices: &[i32],
) -> Result<Vec<Self>, DmapError>
where Self: Sized + Send { ... }
fn read_file_by_indices_lax<P: AsRef<Path>>(
infile: P,
indices: &[i32],
) -> Result<(Vec<Self>, Option<usize>), DmapError>
where Self: Sized + Send { ... }
fn read_file_metadata<P: AsRef<Path>>(
infile: P,
) -> Result<Vec<IndexMap<String, DmapField>>, DmapError>
where Self: Sized + Send { ... }
fn read_file_metadata_by_indices<P: AsRef<Path>>(
infile: P,
indices: &[i32],
) -> Result<Vec<IndexMap<String, DmapField>>, DmapError>
where Self: Sized + Send { ... }
fn check_fields(
field_dict: &mut IndexMap<String, DmapField>,
fields_for_type: &Fields<'_>,
) -> Result<(), DmapError> { ... }
fn coerce(
fields_dict: &mut IndexMap<String, DmapField>,
fields_for_type: &Fields<'_>,
) -> Result<Self, DmapError> { ... }
fn data_to_bytes(
data: &IndexMap<String, DmapField>,
fields_for_type: &Fields<'_>,
) -> Result<(i32, i32, Vec<u8>), DmapError> { ... }
fn inspect_bytes(
&self,
fields_for_type: &Fields<'_>,
) -> Result<Vec<(String, usize, Vec<u8>)>, DmapError> { ... }
fn par_to_bytes(recs: &[Self]) -> Result<Vec<u8>, DmapError> { ... }
fn try_into_bytes(
recs: Vec<IndexMap<String, DmapField>>,
) -> Result<Vec<u8>, DmapError> { ... }
fn write_to_file<P: AsRef<Path>>(
recs: &Vec<Self>,
outfile: P,
bz2: bool,
) -> Result<(), DmapError> { ... }
}Expand description
DMAP record template.
This trait defines functionality for parsing bytes into records, converting records to bytes, and reading from / writing to files.
Required Methods§
Sourcefn new(fields: &mut IndexMap<String, DmapField>) -> Result<Self, DmapError>where
Self: Sized,
fn new(fields: &mut IndexMap<String, DmapField>) -> Result<Self, DmapError>where
Self: Sized,
Creates a new object from the parsed scalars and vectors.
Sourcefn get(&self, key: &str) -> Option<&DmapField>
fn get(&self, key: &str) -> Option<&DmapField>
Returns the field with name key, if it exists in the record.
Sourcefn is_metadata_field(name: &str) -> bool
fn is_metadata_field(name: &str) -> bool
Returns whether name is a metadata field of the record.
Provided Methods§
Sourcefn read_nth_records(
dmap_data: impl Read,
indices: &[i32],
) -> Result<Vec<Self>, DmapError>
fn read_nth_records( dmap_data: impl Read, indices: &[i32], ) -> Result<Vec<Self>, DmapError>
Reads the nth records from dmap_data and parse into instances of Self.
Returns DmapError if dmap_data cannot be read or contains invalid data.
Sourcefn read_nth_records_lax(
dmap_data: impl Read,
indices: &[i32],
) -> Result<(Vec<Self>, Option<usize>), DmapError>
fn read_nth_records_lax( dmap_data: impl Read, indices: &[i32], ) -> Result<(Vec<Self>, Option<usize>), DmapError>
Reads the nth records from dmap_data and parse into instances of Self, if possible.
Returns a 2-tuple, where the first entry is the good records from the front of the buffer, and the second entry is the byte where the first corrupted record starts, if applicable.
Sourcefn read_records(dmap_data: impl Read) -> Result<Vec<Self>, DmapError>
fn read_records(dmap_data: impl Read) -> Result<Vec<Self>, DmapError>
Reads from dmap_data and parses into Vec<Self>.
Returns DmapError if dmap_data cannot be read or contains invalid data.
Sourcefn read_metadata(
dmap_data: impl Read,
) -> Result<Vec<IndexMap<String, DmapField>>, DmapError>
fn read_metadata( dmap_data: impl Read, ) -> Result<Vec<IndexMap<String, DmapField>>, DmapError>
Reads metadata of records from dmap_data and parses into Vec<IndexMap<String, DmapField>>.
Returns DmapError if dmap_data cannot be read or contains invalid data.
Sourcefn read_metadata_by_indices(
dmap_data: impl Read,
indices: &[i32],
) -> Result<Vec<IndexMap<String, DmapField>>, DmapError>
fn read_metadata_by_indices( dmap_data: impl Read, indices: &[i32], ) -> Result<Vec<IndexMap<String, DmapField>>, DmapError>
Reads metadata of the nth records from dmap_data and parses into Vec<IndexMap<String, DmapField>>.
Returns DmapError if dmap_data cannot be read or contains invalid data.
Sourcefn read_records_lax(
dmap_data: impl Read,
) -> Result<(Vec<Self>, Option<usize>), DmapError>
fn read_records_lax( dmap_data: impl Read, ) -> Result<(Vec<Self>, Option<usize>), DmapError>
Reads from dmap_data and parses into Vec<Self>.
Returns a 2-tuple, where the first entry is the good records from the front of the buffer, and the second entry is the byte where the first corrupted record starts, if applicable.
Sourcefn read_file<P: AsRef<Path>>(infile: P) -> Result<Vec<Self>, DmapError>
fn read_file<P: AsRef<Path>>(infile: P) -> Result<Vec<Self>, DmapError>
Read a DMAP file of type Self
Sourcefn read_file_lax<P: AsRef<Path>>(
infile: P,
) -> Result<(Vec<Self>, Option<usize>), DmapError>
fn read_file_lax<P: AsRef<Path>>( infile: P, ) -> Result<(Vec<Self>, Option<usize>), DmapError>
Read a DMAP file of type Self.
If the file is corrupted, it will return the leading uncorrupted records as well as the position corresponding to the start of the first corrupted record.
Sourcefn read_file_by_indices<P: AsRef<Path>>(
infile: P,
indices: &[i32],
) -> Result<Vec<Self>, DmapError>
fn read_file_by_indices<P: AsRef<Path>>( infile: P, indices: &[i32], ) -> Result<Vec<Self>, DmapError>
Reads the nth record(s) of a DMAP file of type Self.
Sourcefn read_file_by_indices_lax<P: AsRef<Path>>(
infile: P,
indices: &[i32],
) -> Result<(Vec<Self>, Option<usize>), DmapError>
fn read_file_by_indices_lax<P: AsRef<Path>>( infile: P, indices: &[i32], ) -> Result<(Vec<Self>, Option<usize>), DmapError>
Reads the nth record(s) of a DMAP file of type Self.
Does not fail on corrupted records; rather, returns (recs, Option<usize>) where
the second value is the byte where record corruption begins, if applicable.
Sourcefn read_file_metadata<P: AsRef<Path>>(
infile: P,
) -> Result<Vec<IndexMap<String, DmapField>>, DmapError>
fn read_file_metadata<P: AsRef<Path>>( infile: P, ) -> Result<Vec<IndexMap<String, DmapField>>, DmapError>
Read the metadata from a DMAP file of type Self
Sourcefn read_file_metadata_by_indices<P: AsRef<Path>>(
infile: P,
indices: &[i32],
) -> Result<Vec<IndexMap<String, DmapField>>, DmapError>
fn read_file_metadata_by_indices<P: AsRef<Path>>( infile: P, indices: &[i32], ) -> Result<Vec<IndexMap<String, DmapField>>, DmapError>
Reads the nth records’ metadata of a DMAP file of type Self.
Sourcefn check_fields(
field_dict: &mut IndexMap<String, DmapField>,
fields_for_type: &Fields<'_>,
) -> Result<(), DmapError>
fn check_fields( field_dict: &mut IndexMap<String, DmapField>, fields_for_type: &Fields<'_>, ) -> Result<(), DmapError>
Checks the validity of an IndexMap as a representation of a DMAP record.
Validity checks include ensuring that no unfamiliar entries exist, that all required scalar and vector fields exist, that all scalar and vector fields are of the expected type, and that vector fields which are expected to have the same dimensions do indeed have the same dimensions.
Sourcefn coerce(
fields_dict: &mut IndexMap<String, DmapField>,
fields_for_type: &Fields<'_>,
) -> Result<Self, DmapError>
fn coerce( fields_dict: &mut IndexMap<String, DmapField>, fields_for_type: &Fields<'_>, ) -> Result<Self, DmapError>
Attempts to massage the entries of an IndexMap into the proper types for a DMAP record.
Sourcefn data_to_bytes(
data: &IndexMap<String, DmapField>,
fields_for_type: &Fields<'_>,
) -> Result<(i32, i32, Vec<u8>), DmapError>
fn data_to_bytes( data: &IndexMap<String, DmapField>, fields_for_type: &Fields<'_>, ) -> Result<(i32, i32, Vec<u8>), DmapError>
Converts the entries of an IndexMap into a raw byte representation, including metadata
about the entries (DMAP key, name\[, dimensions\]).
If all is good, returns a tuple containing:
- the number of scalar fields
- the number of vector fields
- the raw bytes
Sourcefn inspect_bytes(
&self,
fields_for_type: &Fields<'_>,
) -> Result<Vec<(String, usize, Vec<u8>)>, DmapError>
fn inspect_bytes( &self, fields_for_type: &Fields<'_>, ) -> Result<Vec<(String, usize, Vec<u8>)>, DmapError>
Converts the entries of a Record into a raw byte representation, for debugging the conversion.
If all is good, returns a vector containing tuples of:
String: the name of the field ("header"denoting the record header)usize: where the serialized bytes of the field start in the record byte representationVec<u8>the byte representation of the field.
Sourcefn par_to_bytes(recs: &[Self]) -> Result<Vec<u8>, DmapError>
fn par_to_bytes(recs: &[Self]) -> Result<Vec<u8>, DmapError>
Creates the byte representation of a collection of Records.
Ordering of the members is preserved.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".