Skip to content

Commit

Permalink
fix: serde
Browse files Browse the repository at this point in the history
  • Loading branch information
veeso committed Oct 16, 2023
1 parent 1935317 commit df94b2a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ tempfile = "^3"
[features]
default = ["derive", "ratatui", "crossterm"]
derive = ["tuirealm_derive"]
serialize = ["serde"]
serialize = ["serde", "bitflags/serde"]
tui = ["dep:tui"]
crossterm = ["dep:crossterm", "tui?/crossterm", "ratatui?/crossterm"]
termion = ["dep:termion", "tui?/termion", "ratatui?/termion"]
Expand Down
22 changes: 11 additions & 11 deletions src/core/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,13 @@ pub enum Key {
Esc,
}

/// Defines special key states, such as shift, control, alt...
#[derive(Clone, Copy, Hash, Eq, PartialEq, Debug, PartialOrd, Ord)]
#[cfg_attr(feature = "serialize", derive(Deserialize, Serialize))]
pub struct KeyModifiers(u8);

bitflags! {
/// ## KeyModifiers
///
/// Defines special key states, such as shift, control, alt...
#[cfg_attr(feature = "serialize", derive(Deserialize, Serialize), serde(tag = "type"))]
#[derive(Clone, Copy, Hash, Eq, PartialEq, Debug, PartialOrd, Ord)]
pub struct KeyModifiers: u8 {
impl KeyModifiers: u8 {
const NONE = 0b0000_0000;
const SHIFT = 0b0000_0001;
const CONTROL = 0b0000_0010;
Expand Down Expand Up @@ -258,7 +258,7 @@ mod test {
#[cfg(feature = "serialize")]
use tempfile::NamedTempFile;

#[cfg(feature = "serde")]
#[cfg(feature = "serialize")]
fn deserialize<R, S>(mut readable: R) -> S
where
R: Read,
Expand All @@ -276,7 +276,7 @@ mod test {
}
}

#[cfg(feature = "serde")]
#[cfg(feature = "serialize")]
fn serialize<S, W>(serializable: &S, mut writable: W)
where
S: Serialize + Sized,
Expand All @@ -295,22 +295,22 @@ mod test {
}
}

#[cfg(feature = "serde")]
#[cfg(feature = "serialize")]
#[derive(Debug, PartialEq, Deserialize, Serialize)]
struct KeyBindings {
pub quit: KeyEvent,
pub open: KeyEvent,
}

#[cfg(feature = "serde")]
#[cfg(feature = "serialize")]
impl KeyBindings {
pub fn new(quit: KeyEvent, open: KeyEvent) -> Self {
Self { quit, open }
}
}

#[test]
#[cfg(feature = "serde")]
#[cfg(feature = "serialize")]
fn should_serialize_key_bindings() {
let temp = NamedTempFile::new().expect("Failed to open tempfile");
let keys = KeyBindings::new(
Expand Down

0 comments on commit df94b2a

Please sign in to comment.