Skip to content

Commit

Permalink
refactor: remove unnecessary Rc usages
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Aug 30, 2023
1 parent 89154ae commit a9df385
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 29 deletions.
6 changes: 3 additions & 3 deletions src/items/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{accelerator::Accelerator, IsMenuItem, MenuId, MenuItemKind};
/// [`Submenu`]: crate::Submenu
#[derive(Clone)]
pub struct CheckMenuItem {
pub(crate) id: Rc<MenuId>,
pub(crate) id: MenuId,
pub(crate) inner: Rc<RefCell<crate::platform_impl::MenuChild>>,
}

Expand Down Expand Up @@ -47,7 +47,7 @@ impl CheckMenuItem {
None,
);
Self {
id: Rc::new(item.id().clone()),
id: item.id().clone(),
inner: Rc::new(RefCell::new(item)),
}
}
Expand All @@ -65,7 +65,7 @@ impl CheckMenuItem {
) -> Self {
let id = id.into();
Self {
id: Rc::new(id.clone()),
id: id.clone(),
inner: Rc::new(RefCell::new(crate::platform_impl::MenuChild::new_check(
text.as_ref(),
enabled,
Expand Down
10 changes: 5 additions & 5 deletions src/items/icon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{
/// [`Submenu`]: crate::Submenu
#[derive(Clone)]
pub struct IconMenuItem {
pub(crate) id: Rc<MenuId>,
pub(crate) id: MenuId,
pub(crate) inner: Rc<RefCell<crate::platform_impl::MenuChild>>,
}

Expand Down Expand Up @@ -50,7 +50,7 @@ impl IconMenuItem {
None,
);
Self {
id: Rc::new(item.id().clone()),
id: item.id().clone(),
inner: Rc::new(RefCell::new(item)),
}
}
Expand All @@ -68,7 +68,7 @@ impl IconMenuItem {
) -> Self {
let id = id.into();
Self {
id: Rc::new(id.clone()),
id: id.clone(),
inner: Rc::new(RefCell::new(crate::platform_impl::MenuChild::new_icon(
text.as_ref(),
enabled,
Expand Down Expand Up @@ -100,7 +100,7 @@ impl IconMenuItem {
None,
);
Self {
id: Rc::new(item.id().clone()),
id: item.id().clone(),
inner: Rc::new(RefCell::new(item)),
}
}
Expand All @@ -121,7 +121,7 @@ impl IconMenuItem {
) -> Self {
let id = id.into();
Self {
id: Rc::new(id.clone()),
id: id.clone(),
inner: Rc::new(RefCell::new(
crate::platform_impl::MenuChild::new_native_icon(
text.as_ref(),
Expand Down
6 changes: 3 additions & 3 deletions src/items/normal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{accelerator::Accelerator, IsMenuItem, MenuId, MenuItemKind};
/// [`Submenu`]: crate::Submenu
#[derive(Clone)]
pub struct MenuItem {
pub(crate) id: Rc<MenuId>,
pub(crate) id: MenuId,
pub(crate) inner: Rc<RefCell<crate::platform_impl::MenuChild>>,
}

Expand All @@ -30,7 +30,7 @@ impl MenuItem {
pub fn new<S: AsRef<str>>(text: S, enabled: bool, acccelerator: Option<Accelerator>) -> Self {
let item = crate::platform_impl::MenuChild::new(text.as_ref(), enabled, acccelerator, None);
Self {
id: Rc::new(item.id().clone()),
id: item.id().clone(),
inner: Rc::new(RefCell::new(item)),
}
}
Expand All @@ -47,7 +47,7 @@ impl MenuItem {
) -> Self {
let id = id.into();
Self {
id: Rc::new(id.clone()),
id: id.clone(),
inner: Rc::new(RefCell::new(crate::platform_impl::MenuChild::new(
text.as_ref(),
enabled,
Expand Down
4 changes: 2 additions & 2 deletions src/items/predefined.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use keyboard_types::{Code, Modifiers};
/// A predefined (native) menu item which has a predfined behavior by the OS or by this crate.
#[derive(Clone)]
pub struct PredefinedMenuItem {
pub(crate) id: Rc<MenuId>,
pub(crate) id: MenuId,
pub(crate) inner: Rc<RefCell<crate::platform_impl::MenuChild>>,
}

Expand Down Expand Up @@ -162,7 +162,7 @@ impl PredefinedMenuItem {
text.map(|t| t.as_ref().to_string()),
);
Self {
id: Rc::new(item.id().clone()),
id: item.id().clone(),
inner: Rc::new(RefCell::new(item)),
}
}
Expand Down
20 changes: 4 additions & 16 deletions src/platform_impl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,31 +46,19 @@ impl MenuChild {
}
MenuItemType::MenuItem => {
let id = c.borrow().id().clone();
MenuItemKind::MenuItem(MenuItem {
id: Rc::new(id),
inner: c,
})
MenuItemKind::MenuItem(MenuItem { id, inner: c })
}
MenuItemType::Predefined => {
let id = c.borrow().id().clone();
MenuItemKind::Predefined(PredefinedMenuItem {
id: Rc::new(id),
inner: c,
})
MenuItemKind::Predefined(PredefinedMenuItem { id, inner: c })
}
MenuItemType::Check => {
let id = c.borrow().id().clone();
MenuItemKind::Check(CheckMenuItem {
id: Rc::new(id),
inner: c,
})
MenuItemKind::Check(CheckMenuItem { id, inner: c })
}
MenuItemType::Icon => {
let id = c.borrow().id().clone();
MenuItemKind::Icon(IconMenuItem {
id: Rc::new(id),
inner: c,
})
MenuItemKind::Icon(IconMenuItem { id, inner: c })
}
}
}
Expand Down

0 comments on commit a9df385

Please sign in to comment.