[pve-devel] [PATCH installer 1/3] tui: bootdisk: refactor Rc<RefCell<..>> type into custom type

Christoph Heiss c.heiss at proxmox.com
Tue Jul 25 10:35:40 CEST 2023


Will be used/passed around quite a lot of times due to future changes,
so simplify it a bit.

No functional changes.

Signed-off-by: Christoph Heiss <c.heiss at proxmox.com>
---
 proxmox-tui-installer/src/views/bootdisk.rs | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/proxmox-tui-installer/src/views/bootdisk.rs b/proxmox-tui-installer/src/views/bootdisk.rs
index 6ef814f..d0f5abf 100644
--- a/proxmox-tui-installer/src/views/bootdisk.rs
+++ b/proxmox-tui-installer/src/views/bootdisk.rs
@@ -16,9 +16,13 @@ use crate::options::{
 };
 use crate::setup::ProxmoxProduct;
 
+/// Convience wrapper when needing to take a (interior-mutable) reference to `BootdiskOptions`.
+/// Interior mutability is safe for this case, as it is completely single-threaded.
+pub type BootdiskOptionsRef = Rc<RefCell<BootdiskOptions>>;
+
 pub struct BootdiskOptionsView {
     view: LinearLayout,
-    advanced_options: Rc<RefCell<BootdiskOptions>>,
+    advanced_options: BootdiskOptionsRef,
 }
 
 impl BootdiskOptionsView {
@@ -519,14 +523,14 @@ impl ViewWrapper for ZfsBootdiskOptionsView {
     cursive::wrap_impl!(self.view: MultiDiskOptionsView<FormView>);
 }
 
-fn advanced_options_view(disks: &[Disk], options: Rc<RefCell<BootdiskOptions>>) -> impl View {
+fn advanced_options_view(disks: &[Disk], options_ref: BootdiskOptionsRef) -> impl View {
     Dialog::around(AdvancedBootdiskOptionsView::new(
         disks,
-        &(*options).borrow(),
+        &(*options_ref).borrow(),
     ))
     .title("Advanced bootdisk options")
     .button("Ok", {
-        let options_ref = options.clone();
+        let options_ref = options_ref.clone();
         move |siv| {
             let options = siv
                 .call_on_name("advanced-bootdisk-options-dialog", |view: &mut Dialog| {
@@ -555,7 +559,7 @@ fn advanced_options_view(disks: &[Disk], options: Rc<RefCell<BootdiskOptions>>)
 
             siv.pop_layer();
             if let Some(options) = options {
-                *(*options_ref).borrow_mut() = options;
+                *options_ref.borrow_mut() = options;
             }
         }
     })
-- 
2.41.0






More information about the pve-devel mailing list