Skip to content

Commit

Permalink
Merge pull request #136 from AeroRust/feat/derive-more-traits
Browse files Browse the repository at this point in the history
feat: derive defmt::Format and Clone/Copy for additional structs:
  • Loading branch information
elpiel authored Nov 22, 2024
2 parents b56b2d1 + 32f3e77 commit 18c69db
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 60 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ jobs:
- uses: actions/checkout@v4

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
# When passing an explicit toolchain as an input instead of @rev,
# you'll want to use "dtolnay/rust-toolchain@master" as the revision of the action.
uses: dtolnay/rust-toolchain@master
with:
components: rust-src
toolchain: ${{ matrix.rust }}
Expand Down
102 changes: 51 additions & 51 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ readme = "README.md"

edition = "2021"
# Update README.md and ci.yml when updating the MSRV!
# When bumping MSRV to 1.81, make sure to use core::error::Error.
rust-version = "1.70.0"

[package.metadata.docs.rs]
Expand All @@ -40,7 +41,7 @@ nom = { version = "7.1", default-features = false }
num-traits = { version = "0.2", default-features = false, features = ["libm"] }
cfg-if = "1"
serde = { version = "1.0", default-features = false, optional = true }
serde_with = { version = "~3.9", default-features = false, optional = true }
serde_with = { version = "~3.11", default-features = false, optional = true }

defmt = { version = "0.3", optional = true }

Expand Down
2 changes: 2 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use core::fmt;

use crate::{sentences::GnssType, SentenceType};

#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
#[derive(Debug, PartialEq)]
pub enum Error<'a> {
/// The provided input was not a proper UTF-8 string
Expand All @@ -19,6 +20,7 @@ pub enum Error<'a> {
/// An unknown [`GnssType`] was found in the NMEA message.
UnknownGnssType(&'a str),
/// The sentence could not be parsed because its format was invalid.
#[cfg_attr(feature = "defmt-03", defmt(defmt::Debug2Format))]
ParsingError(nom::Err<nom::error::Error<&'a str>>),
/// The sentence was too long to be parsed, our current limit is `SENTENCE_MAX_LEN` characters.
SentenceLength(usize),
Expand Down
7 changes: 3 additions & 4 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -773,10 +773,9 @@ define_sentence_type_enum! {
///
/// - [`SentenceType::RMZ`]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
#[repr(u32)]
#[allow(rustdoc::bare_urls)]
pub enum SentenceType {
/// AAM - Waypoint Arrival Alarm
///
Expand Down Expand Up @@ -832,7 +831,7 @@ define_sentence_type_enum! {
BWR,
/// BWW - Bearing - Waypoint to Waypoint
///
/// https://gpsd.gitlab.io/gpsd/NMEA.html#_bww_bearing_waypoint_to_waypoint
/// <https://gpsd.gitlab.io/gpsd/NMEA.html#_bww_bearing_waypoint_to_waypoint>
///
/// Type: `Waypoints and tacks`
BWW,
Expand Down Expand Up @@ -927,7 +926,7 @@ define_sentence_type_enum! {
GSA,
/// GST - GPS Pseudorange Noise Statistics
///
/// https://gpsd.gitlab.io/gpsd/NMEA.html#_gst_gps_pseudorange_noise_statistics
/// <https://gpsd.gitlab.io/gpsd/NMEA.html#_gst_gps_pseudorange_noise_statistics>
GST,
/// GSV - Satellites in view
///
Expand Down
3 changes: 1 addition & 2 deletions src/sentences/gll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ use crate::{
/// | | | | | | |
/// $--GLL,ddmm.mm,a,dddmm.mm,a,hhmmss.ss,a,m*hh<CR><LF>
/// ```
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
#[derive(Debug, PartialEq)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct GllData {
pub latitude: Option<f64>,
pub longitude: Option<f64>,
Expand Down
Loading

0 comments on commit 18c69db

Please sign in to comment.