Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MTW sentence parser #77

Merged
merged 3 commits into from
Feb 10, 2023
Merged

Conversation

JasminFragnaud
Copy link

#54

Copy link
Member

@elpiel elpiel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for your fist-time contribution 🎉

I have left a few notes on the PR, I'm eager to merge it asap 😊

let (i, temperature_value) = opt(float)(i)?;
let (i, unit) = opt(preceded(char(','), one_of("C")))(i)?;
let unit = unit.map(|ch| match ch {
'C' => MtwUnit::Celcius,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any other options apart from Celsius? I didn't find anything else, so maybe it's a good idea to just remove the field from the MtwData. The documentation can be specific for the field - only Celsius.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've had searched for this but it's kinda strange, it's described as a field in the documentation (and implemented as is in other libs) but this field seems to can only be celsius. Also didn't find any example with something else, so i assume we can remove it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!


#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MtwUnit {
Celcius,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's actually a small typo, should be Celsius with an s

Comment on lines 25 to 26
pub temperature: Option<f32>,
pub temperature_unit: Option<MtwUnit>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Let's just leave temperature and add a documentation block /// that it is only "degrees Celsius"
  2. use double (f64) instead. We've discussed this before and we should unify the api to always use f64.

assert_eq!(s.checksum, 0x20);
let mtw_data = parse_mtw(s).unwrap();
assert_eq!(Some(17.9), mtw_data.temperature);
assert_eq!(None, mtw_data.temperature_unit);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test should cause an error instead of Option::None

Copy link
Member

@elpiel elpiel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you again for your contribution

@elpiel elpiel merged commit 0779bba into AeroRust:main Feb 10, 2023
@elpiel elpiel linked an issue Feb 10, 2023 that may be closed by this pull request
@JasminFragnaud JasminFragnaud deleted the mtw-sentence-parsing branch February 11, 2023 11:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Supporting additional sentences
2 participants