Skip to content

Commit f1aaa1b

Browse files
djcrami3l
authored andcommitted
Internalize interior mutability for Notifier
1 parent 7acd8b2 commit f1aaa1b

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/cli/common.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,20 +126,20 @@ pub(crate) fn read_line() -> Result<String> {
126126

127127
#[derive(Default)]
128128
struct NotifyOnConsole {
129-
ram_notice_shown: bool,
129+
ram_notice_shown: RefCell<bool>,
130130
verbose: bool,
131131
}
132132

133133
impl NotifyOnConsole {
134-
fn handle(&mut self, n: Notification<'_>) {
134+
fn handle(&self, n: Notification<'_>) {
135135
if let Notification::Install(dist_notifications::Notification::Utils(
136136
util_notifications::Notification::SetDefaultBufferSize(_),
137137
)) = &n
138138
{
139-
if self.ram_notice_shown {
139+
if *self.ram_notice_shown.borrow() {
140140
return;
141141
} else {
142-
self.ram_notice_shown = true;
142+
*self.ram_notice_shown.borrow_mut() = true;
143143
}
144144
};
145145
let level = n.level();
@@ -169,25 +169,25 @@ impl NotifyOnConsole {
169169

170170
struct Notifier {
171171
tracker: Arc<Mutex<DownloadTracker>>,
172-
notifier: RefCell<NotifyOnConsole>,
172+
notifier: NotifyOnConsole,
173173
}
174174

175175
impl Notifier {
176176
fn new(verbose: bool, quiet: bool) -> Self {
177177
Self {
178178
tracker: DownloadTracker::new_with_display_progress(!quiet),
179-
notifier: RefCell::new(NotifyOnConsole {
179+
notifier: NotifyOnConsole {
180180
verbose,
181181
..Default::default()
182-
}),
182+
},
183183
}
184184
}
185185

186186
fn handle(&self, n: Notification<'_>) {
187187
if self.tracker.lock().unwrap().handle_notification(&n) {
188188
return;
189189
}
190-
self.notifier.borrow_mut().handle(n);
190+
self.notifier.handle(n);
191191
}
192192
}
193193

0 commit comments

Comments
 (0)