rust-analyzer/crates/ra_hir/src/util.rs

13 lines
388 B
Rust
Raw Normal View History

//! Internal utility functions.
use std::sync::Arc;
/// Helper for mutating `Arc<[T]>` (i.e. `Arc::make_mut` for Arc slices).
/// The underlying values are cloned if there are other strong references.
2019-10-14 10:50:12 +00:00
pub(crate) fn make_mut_slice<T: Clone>(a: &mut Arc<[T]>) -> &mut [T] {
if Arc::get_mut(a).is_none() {
*a = a.iter().cloned().collect();
}
2019-10-14 10:50:12 +00:00
Arc::get_mut(a).unwrap()
}