Skip to content

Commit 9d4849a

Browse files
tgross35djc
authored andcommitted
Change OnceCell to OnceLock in TabExpandedString
The change at [1] stores some data in a `OnceCell`, which made `ProgressStyle` no longer `Sync`. Fix this by changing the `OnceCell` to a `OnceLock`, and add a static test that all relevant public types are `Send` and `Sync`. [1]: #684
1 parent c340e9f commit 9d4849a

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

src/lib.rs

+18
Original file line numberDiff line numberDiff line change
@@ -272,3 +272,21 @@ pub use crate::rayon::ParallelProgressIterator;
272272
pub use crate::state::{ProgressFinish, ProgressState};
273273
pub use crate::style::ProgressStyle;
274274
pub use crate::term_like::TermLike;
275+
276+
#[cfg(test)]
277+
mod tests {
278+
use super::*;
279+
280+
#[allow(dead_code)]
281+
trait MustBeThreadSafe: Send + Sync {}
282+
283+
// Ensure that the following types are `Send + Sync`
284+
impl MustBeThreadSafe for MultiProgress {}
285+
impl MustBeThreadSafe for MultiProgressAlignment {}
286+
impl MustBeThreadSafe for ProgressBar {}
287+
impl MustBeThreadSafe for ProgressBarIter<()> {}
288+
impl MustBeThreadSafe for ProgressFinish {}
289+
impl MustBeThreadSafe for ProgressState {}
290+
impl MustBeThreadSafe for ProgressStyle {}
291+
impl MustBeThreadSafe for WeakProgressBar {}
292+
}

src/state.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::borrow::Cow;
2-
use std::cell::OnceCell;
32
use std::io;
4-
use std::sync::Arc;
3+
use std::sync::{Arc, OnceLock};
54
use std::time::Duration;
65
#[cfg(not(target_arch = "wasm32"))]
76
use std::time::Instant;
@@ -355,7 +354,7 @@ pub(crate) enum TabExpandedString {
355354
NoTabs(Cow<'static, str>),
356355
WithTabs {
357356
original: Cow<'static, str>,
358-
expanded: OnceCell<String>,
357+
expanded: OnceLock<String>,
359358
tab_width: usize,
360359
},
361360
}
@@ -368,7 +367,7 @@ impl TabExpandedString {
368367
Self::WithTabs {
369368
original: s,
370369
tab_width,
371-
expanded: OnceCell::new(),
370+
expanded: OnceLock::new(),
372371
}
373372
}
374373
}

0 commit comments

Comments
 (0)