diff --git a/Cargo.toml b/Cargo.toml index c39d9bd..5298fa3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/settings.rs b/src/settings.rs index d5f6278..bfa8e79 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -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)] @@ -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.