tinymist_std/concepts/takable.rs
1use std::sync::Arc;
2
3/// Trait for values being taken.
4pub trait TakeAs<T> {
5 /// Takes the inner value if there is exactly one strong reference and
6 /// clones it otherwise.
7 fn take(self) -> T;
8}
9
10impl<T: Clone> TakeAs<T> for Arc<T> {
11 fn take(self) -> T {
12 match Arc::try_unwrap(self) {
13 Ok(v) => v,
14 Err(rc) => (*rc).clone(),
15 }
16 }
17}