2022-10-08 20:46:43 +00:00
|
|
|
#![allow(dead_code)]
|
|
|
|
|
2022-10-12 02:24:00 +00:00
|
|
|
pub mod model;
|
|
|
|
pub mod prelude;
|
2022-10-08 20:46:43 +00:00
|
|
|
|
|
|
|
use std::num::{ParseFloatError, ParseIntError};
|
|
|
|
use std::str::ParseBoolError;
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum DsnRespParseError {
|
|
|
|
AttrMissing(String),
|
|
|
|
ParseIntErr(ParseIntError),
|
|
|
|
ParseFloatErr(ParseFloatError),
|
|
|
|
ParseBoolErr(ParseBoolError),
|
|
|
|
XMLReaderError(xml::reader::Error),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<ParseIntError> for DsnRespParseError {
|
|
|
|
fn from(error: ParseIntError) -> Self {
|
|
|
|
DsnRespParseError::ParseIntErr(error)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<ParseFloatError> for DsnRespParseError {
|
|
|
|
fn from(error: ParseFloatError) -> Self {
|
|
|
|
DsnRespParseError::ParseFloatErr(error)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<ParseBoolError> for DsnRespParseError {
|
|
|
|
fn from(error: ParseBoolError) -> Self {
|
|
|
|
DsnRespParseError::ParseBoolErr(error)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<xml::reader::Error> for DsnRespParseError {
|
|
|
|
fn from(error: xml::reader::Error) -> Self {
|
|
|
|
DsnRespParseError::XMLReaderError(error)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl std::fmt::Display for DsnRespParseError {
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
match self {
|
|
|
|
DsnRespParseError::AttrMissing(attr) => write!(f, "Attr missing: {}", attr),
|
|
|
|
DsnRespParseError::ParseIntErr(e) => write!(f, "Int parse error: {}", e),
|
|
|
|
DsnRespParseError::ParseFloatErr(e) => write!(f, "Int parse error: {}", e),
|
|
|
|
DsnRespParseError::ParseBoolErr(e) => write!(f, "Bool parse error: {}", e),
|
|
|
|
DsnRespParseError::XMLReaderError(e) => write!(f, "XML Parse error: {}", e),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use crate::model::DsnResponse;
|
|
|
|
use std::fs::File;
|
|
|
|
use std::io::BufReader;
|
|
|
|
|
|
|
|
fn parse_test_file() -> DsnResponse {
|
|
|
|
let example_file = File::open("data/dsn.xml").unwrap();
|
|
|
|
let buf_reader = BufReader::new(example_file);
|
|
|
|
DsnResponse::from_xml_response(buf_reader).unwrap()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_parse() {
|
|
|
|
let response = parse_test_file();
|
|
|
|
println!("{:?}", response.stations)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_get_active_targets() {
|
|
|
|
let response = parse_test_file();
|
|
|
|
println!("{:?}", response.get_active_targets());
|
|
|
|
}
|
|
|
|
}
|