refactor: wrap Menu.id in Rc

This commit is contained in:
Amr Bashir 2023-08-31 02:37:16 +03:00
parent 89154aede0
commit 8d832c06f4
No known key found for this signature in database
GPG key ID: BBD7A47A2003FF33
2 changed files with 8 additions and 3 deletions

5
.changes/menu-rc.md Normal file
View file

@ -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.

View file

@ -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<MenuId>,
inner: Rc<RefCell<crate::platform_impl::Menu>>,
}
@ -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<I: Into<MenuId>>(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)))),
}
}