From 8d832c06f4e810278c0da129063231f880c3f918 Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Thu, 31 Aug 2023 02:37:16 +0300 Subject: [PATCH] refactor: wrap `Menu.id` in `Rc` --- .changes/menu-rc.md | 5 +++++ src/menu.rs | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 .changes/menu-rc.md diff --git a/.changes/menu-rc.md b/.changes/menu-rc.md new file mode 100644 index 0000000..98c8ef2 --- /dev/null +++ b/.changes/menu-rc.md @@ -0,0 +1,5 @@ +--- +"muda": "patch" +--- + +Wrapped the `id` field of the `Menu` struct in an `Rc` to be consistent with other menu structs and make it cheaper to clone. diff --git a/src/menu.rs b/src/menu.rs index 1067919..9b0042e 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -10,7 +10,7 @@ use crate::{util::AddOp, ContextMenu, IsMenuItem, MenuId, MenuItemKind, Position /// and used as the app global menu on macOS. #[derive(Clone)] pub struct Menu { - id: MenuId, + id: Rc, inner: Rc>, } @@ -25,7 +25,7 @@ impl Menu { pub fn new() -> Self { let menu = crate::platform_impl::Menu::new(None); Self { - id: menu.id().clone(), + id: Rc::new(menu.id().clone()), inner: Rc::new(RefCell::new(menu)), } } @@ -34,7 +34,7 @@ impl Menu { pub fn with_id>(id: I) -> Self { let id = id.into(); Self { - id: id.clone(), + id: Rc::new(id.clone()), inner: Rc::new(RefCell::new(crate::platform_impl::Menu::new(Some(id)))), } }