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§
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_first_record(dmap_data: impl Read) -> Result<Self, DmapError>
fn read_first_record(dmap_data: impl Read) -> Result<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_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<Self>.
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 sniff_file<P: AsRef<Path>>(infile: P) -> Result<Self, DmapError>
fn sniff_file<P: AsRef<Path>>(infile: P) -> Result<Self, DmapError>
Reads the first record of a DMAP file of type Self.
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 parse_metadata(
cursor: &mut Cursor<Vec<u8>>,
) -> Result<IndexMap<String, DmapField>, DmapError>where
Self: Sized,
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.
Sourcefn parse_record(cursor: &mut Cursor<Vec<u8>>) -> Result<Self, DmapError>where
Self: Sized,
fn parse_record(cursor: &mut Cursor<Vec<u8>>) -> Result<Self, DmapError>where
Self: Sized,
Reads a record from cursor.
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 into_bytes(recs: &Vec<Self>) -> Result<Vec<u8>, DmapError>
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.
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.