Skip to content

Commit

Permalink
CharSize and StopBits serialize as integers now.
Browse files Browse the repository at this point in the history
  • Loading branch information
avocadochicken committed Nov 7, 2023
1 parent ca9f0a5 commit ad345ff
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ windows = []
# Add #[doc(cfg(...))] annotations to platform specific items for better documentation (requires nightly toolchain).
doc-cfg = []

serde = ["dep:serde"]
serde = ["dep:serde", "dep:serde_repr"]

[dependencies]
serde = { version = "1.0", features = ["derive"], optional = true }
serde_repr = { version = "0.1", optional = true }

[target.'cfg(unix)'.dependencies]
libc = "0.2.109"
Expand Down
21 changes: 12 additions & 9 deletions src/settings.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use {
serde::{Deserialize, Serialize},
serde_repr::{Serialize_repr, Deserialize_repr},
};

/// The settings of a serial port.
#[derive(Clone)]
Expand All @@ -19,30 +22,30 @@ pub const COMMON_BAUD_RATES: &[u32] = &[

/// The number of bits per character for a serial port.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", derive(Serialize_repr, Deserialize_repr), repr(u8))]
pub enum CharSize {
/// Characters of 5 bits.
Bits5,
Bits5 = 5,

/// Characters of 6 bits.
Bits6,
Bits6 = 6,

/// Characters of 7 bits.
Bits7,
Bits7 = 7,

/// Characters of 8 bits.
Bits8,
Bits8 = 8,
}

/// The number of stop bits per character for a serial port.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", derive(Serialize_repr, Deserialize_repr), repr(u8))]
pub enum StopBits {
/// One stop bit.
One,
One = 1,

/// Two stop bit.
Two,
Two = 2,
}

/// The type of parity check for a serial port.
Expand Down

0 comments on commit ad345ff

Please sign in to comment.