diff --git a/src/headparse.rs b/src/headparse.rs index ece9c16..94911b4 100644 --- a/src/headparse.rs +++ b/src/headparse.rs @@ -2,9 +2,11 @@ use std::{collections::HashMap, u64, vec}; use crate::SignalFormat; -/// Record information obtained from the header. +/// Holds the essential header information about the record, like the amount of +/// signals, and the sampling frequency. /// -/// Only the `name`, `signal_count`, and `sampling_freq` values are required by default. +/// Only the `name`, `signal_count`, and `sampling_freq` values are required by +/// default. #[derive(Debug, Clone)] struct Record { name: String, @@ -19,7 +21,11 @@ struct Record { } impl Record { - /// Attempts to generate the record information from a string of the argument line + /// Attempts to generate the record information from a string of the argument + /// line that's provided by the WFDB header file + /// + /// Returns a `Result`, with the error field potentially + /// describing why the parsing operation failed pub fn from_str(argument_line: &str) -> Result { let args: Vec<&str> = argument_line.split(' ').collect(); if args.len() < 2 { @@ -134,6 +140,8 @@ impl Record { } } +/// Keys for all the data that can possibly be parsed from the values appended +/// to the ADC block #[derive(Debug, Eq, Hash, PartialEq)] enum AdcBlockKeys { Gain, @@ -141,7 +149,9 @@ enum AdcBlockKeys { Units } - +/// Holds the information relevant to individual signals and their specifications +/// +/// By minimum, only carries the `filename`, `format`, and `adc_zero` attributes #[derive(Debug, Clone)] struct SignalSpec { filename: String, @@ -161,11 +171,14 @@ struct SignalSpec { } impl SignalSpec { - /// Attempts to generate a valid signal specification struct from a supplied string. - /// Returns a `Result` containing possible error information. + /// Attempts to generate a valid signal specification struct from a supplied + /// string. + /// Returns a `Result` containing possible error information + /// relevant to parsing failures. /// /// ## Arguments - /// - `argument_line` - argument line for the signal specification, taken from header file + /// - `argument_line` - argument line for the signal specification, taken + /// from header file pub fn from_str(argument_line: &str) -> Result { let args: Vec<&str> = argument_line.split(' ').collect(); @@ -308,8 +321,10 @@ impl SignalSpec { Ok(value) => { initial_val = Some(value); }, - Err(_) => {} // Standard: If this field is missing, adc_zero value is presumed. + // Standard: If this field is missing, + // the adc_zero value is presumed. // We do this on the data parsing part. + Err(_) => {} } if args.len() <= 6 { @@ -361,6 +376,8 @@ impl SignalSpec { ) } + /// Parses the WFDB signal format from the format number, if it exists and + /// is implemented fn parse_format(formatnum: u64) -> SignalFormat { match formatnum { 16 => SignalFormat::Format16, @@ -370,6 +387,9 @@ impl SignalSpec { } } +/// Holds all the possible data from the WFDB header file, those being the record +/// line data and all the possible signal specifications present on the following +/// lines #[derive(Debug, Clone)] pub struct Header { record: Option, @@ -386,6 +406,8 @@ impl Header { Header { record: None, signal_specs: vec![] } } + /// Creates a Header from a supplied Record struct. Initializes the + /// signal_specs vector fn from_record(record: Record) -> Header { Header { record: Some(record), signal_specs: vec![] } } @@ -402,7 +424,10 @@ impl Header { } } -/// Attempts to parse the header file +/// Attempts to parse the header file. +/// +/// Returns a Result either containing the `Header` struct, or the +/// error string describing why we couldn't parse the header. pub fn parse_header(header_data: &str) -> Result { let header_lines: Vec<&str> = header_data.split("\n").collect(); let mut found_record: bool = false;