From 47d1808090dc8b064417d5aae192b924fdafaf58 Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Wed, 16 Aug 2023 19:37:19 +0300 Subject: [PATCH] feat: derive serde for more types --- .changes/serde.md | 5 +++++ src/about_metadata.rs | 1 + src/accelerator.rs | 1 + src/icon.rs | 1 + src/lib.rs | 2 ++ src/menu_id.rs | 1 + 6 files changed, 11 insertions(+) create mode 100644 .changes/serde.md diff --git a/.changes/serde.md b/.changes/serde.md new file mode 100644 index 0000000..fb5611a --- /dev/null +++ b/.changes/serde.md @@ -0,0 +1,5 @@ +--- +"muda": "patch" +--- + +Derive `serde` for more types. diff --git a/src/about_metadata.rs b/src/about_metadata.rs index f6a3157..af0955c 100644 --- a/src/about_metadata.rs +++ b/src/about_metadata.rs @@ -2,6 +2,7 @@ use crate::icon::Icon; /// Application metadata for the [`PredefinedMenuItem::about`](crate::PredefinedMenuItem::about). #[derive(Debug, Clone, Default)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct AboutMetadata { /// Sets the application name. pub name: Option, diff --git a/src/accelerator.rs b/src/accelerator.rs index 4e5b2c5..5eff89b 100644 --- a/src/accelerator.rs +++ b/src/accelerator.rs @@ -39,6 +39,7 @@ pub const CMD_OR_CTRL: Modifiers = Modifiers::CONTROL; /// of modifier keys (provided by [`Modifiers`](crate::accelerator::Modifiers)) and /// one key ([`Code`](crate::accelerator::Code)). #[derive(Debug, Clone, PartialEq, Eq, Hash, Copy)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Accelerator { pub(crate) mods: Modifiers, pub(crate) key: Code, diff --git a/src/icon.rs b/src/icon.rs index ec62bb3..1429453 100644 --- a/src/icon.rs +++ b/src/icon.rs @@ -171,6 +171,7 @@ impl Icon { /// /// - **Windows / Linux**: Unsupported. #[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum NativeIcon { /// An add item template image. Add, diff --git a/src/lib.rs b/src/lib.rs index 45fd17f..349437a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -259,6 +259,7 @@ pub unsafe trait IsMenuItem { } #[derive(Debug, PartialEq, PartialOrd, Clone, Copy)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub(crate) enum MenuItemType { MenuItem, Submenu, @@ -324,6 +325,7 @@ pub trait ContextMenu { /// Describes a menu event emitted when a menu item is activated #[derive(Debug, Clone)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct MenuEvent { /// Id of the menu item which triggered this event pub id: MenuId, diff --git a/src/menu_id.rs b/src/menu_id.rs index 4520256..2403684 100644 --- a/src/menu_id.rs +++ b/src/menu_id.rs @@ -2,6 +2,7 @@ use std::{convert::Infallible, str::FromStr}; /// An unique id that is associated with a menu or a menu item. #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Default, Hash)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct MenuId(pub String); impl MenuId {