Record

Trait Record 

Source
pub trait Record<'a>:
    Debug
    + Send
    + Sync
    + TryFrom<IndexMap<String, DmapField>, Error = DmapError> {
Show 23 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_first_record(dmap_data: impl Read) -> Result<Self, 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_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 sniff_file<P: AsRef<Path>>(infile: P) -> Result<Self, 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 parse_metadata( cursor: &mut Cursor<Vec<u8>>, ) -> Result<IndexMap<String, DmapField>, DmapError> where Self: Sized { ... } fn parse_record(cursor: &mut Cursor<Vec<u8>>) -> Result<Self, DmapError> where Self: Sized { ... } 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 into_bytes(recs: &Vec<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, ) -> 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§

Source

fn new(fields: &mut IndexMap<String, DmapField>) -> Result<Self, DmapError>
where Self: Sized,

Creates a new object from the parsed scalars and vectors.

Source

fn inner(self) -> IndexMap<String, DmapField>

Gets the underlying data of self.

Source

fn get(&self, key: &str) -> Option<&DmapField>

Returns the field with name key, if it exists in the record.

Source

fn keys(&self) -> Vec<&String>

Returns the names of all fields stored in the record.

Source

fn is_metadata_field(name: &str) -> bool

Returns whether name is a metadata field of the record.

Source

fn to_bytes(&self) -> Result<Vec<u8>, DmapError>

Attempts to copy self to a raw byte representation.

Provided Methods§

Source

fn read_first_record(dmap_data: impl Read) -> Result<Self, DmapError>
where Self: Sized + Send,

Reads from dmap_data and parses into Vec<Self>.

Returns DmapError if dmap_data cannot be read or contains invalid data.

Source

fn read_records(dmap_data: impl Read) -> Result<Vec<Self>, DmapError>
where Self: Sized + Send,

Reads from dmap_data and parses into Vec<Self>.

Returns DmapError if dmap_data cannot be read or contains invalid data.

Source

fn read_metadata( dmap_data: impl Read, ) -> Result<Vec<IndexMap<String, DmapField>>, DmapError>
where Self: Sized + Send,

Reads metadata of records from dmap_data and parses into Vec<Self>.

Returns DmapError if dmap_data cannot be read or contains invalid data.

Source

fn read_records_lax( dmap_data: impl Read, ) -> Result<(Vec<Self>, Option<usize>), DmapError>
where Self: Sized + Send,

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.

Source

fn read_file<P: AsRef<Path>>(infile: P) -> Result<Vec<Self>, DmapError>
where Self: Sized + Send,

Read a DMAP file of type Self

Source

fn read_file_lax<P: AsRef<Path>>( infile: P, ) -> Result<(Vec<Self>, Option<usize>), DmapError>
where Self: Sized + Send,

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.

Source

fn sniff_file<P: AsRef<Path>>(infile: P) -> Result<Self, DmapError>
where Self: Sized + Send,

Reads the first record of a DMAP file of type Self.

Source

fn read_file_metadata<P: AsRef<Path>>( infile: P, ) -> Result<Vec<IndexMap<String, DmapField>>, DmapError>
where Self: Sized + Send,

Read the metadata from a DMAP file of type Self

Source

fn parse_metadata( cursor: &mut Cursor<Vec<u8>>, ) -> Result<IndexMap<String, DmapField>, DmapError>
where Self: Sized,

Reads a record from cursor, only keeping the metadata fields.

Source

fn parse_record(cursor: &mut Cursor<Vec<u8>>) -> Result<Self, DmapError>
where Self: Sized,

Reads a record from cursor.

Source

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.

Source

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.

Source

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
Source

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 representation
  • Vec<u8> the byte representation of the field.
Source

fn into_bytes(recs: &Vec<Self>) -> Result<Vec<u8>, DmapError>

Creates the byte represenation of a collection of Records.

Ordering of the members is preserved.

Source

fn try_into_bytes( recs: Vec<IndexMap<String, DmapField>>, ) -> Result<Vec<u8>, DmapError>

Attempts to convert recs to Self then convert to bytes.

Source

fn write_to_file<P: AsRef<Path>>( recs: &Vec<Self>, outfile: P, ) -> Result<(), DmapError>

Writes a collection of Records to outfile.

Prefer using the specific functions, e.g. write_dmap, write_rawacf, etc. for their specific field checks.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§