use radio_code_calculator::{RadioCodeCalculator, RadioCodeCalculatorError, RadioErrors};
#[tokio::main]
async fn main() {
let my_radio_code_calculator =
RadioCodeCalculator::new(Some("ABCD-ABCD-ABCD-ABCD".to_string()));
match my_radio_code_calculator.info("ford-m-series").await {
Ok(info) => {
let radio_model = &info.radio_model;
println!("Radio model name - {}<br>", radio_model.name);
println!(
"Max. length of the radio serial number - {}<br>",
radio_model.serial_max_len
);
println!(
"Regex pattern for the radio serial number - {}<br>",
radio_model.serial_regex_pattern()
);
if radio_model.extra_max_len > 0 {
println!(
"Max. length of the radio extra data - {}<br>",
radio_model.extra_max_len
);
println!(
"Regex pattern for the radio extra data - {:?}<br>",
radio_model.extra_regex_pattern()
);
println!("<br>");
}
}
Err(e) => match e {
RadioCodeCalculatorError::ApiError(v) => {
if v["error"].as_i64() == Some(RadioErrors::INVALID_LICENSE as i64) {
println!("Invalid license key!");
} else {
println!(
"Something unexpected happen while trying to login to the service (error code {:?}).",
v["error"]
);
}
}
RadioCodeCalculatorError::InvalidLicense => println!("Invalid license key!"),
RadioCodeCalculatorError::Transport(msg) => println!("Connection error: {msg}"),
},
}
}