Trait re_sdk::external::arrow2::datatypes::ArcExt

source ·
pub trait ArcExt<T> {
    // Required method
    fn unwrap_or_clone_polyfill(this: Self) -> T;
}
Expand description

An extension trait to polyfill Arc::unwrap_or_clone from the nightly stdlib.

Required Methods§

source

fn unwrap_or_clone_polyfill(this: Self) -> T

If we have the only reference to T then unwrap it. Otherwise, clone T and return the clone.

Assuming arc_t is of type Arc<T>, this function is functionally equivalent to (*arc_t).clone(), but will avoid cloning the inner value where possible.

§Examples
let inner = String::from("test");
let ptr = inner.as_ptr();

let arc = Arc::new(inner);
let inner = ArcExt::unwrap_or_clone_polyfill(arc);
// The inner value was not cloned
assert!(ptr::eq(ptr, inner.as_ptr()));

let arc = Arc::new(inner);
let arc2 = arc.clone();
let inner = ArcExt::unwrap_or_clone_polyfill(arc);
// Because there were 2 references, we had to clone the inner value.
assert!(!ptr::eq(ptr, inner.as_ptr()));
// `arc2` is the last reference, so when we unwrap it we get back
// the original `String`.
let inner = ArcExt::unwrap_or_clone_polyfill(arc2);
assert!(ptr::eq(ptr, inner.as_ptr()));

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<T> ArcExt<T> for Arc<T>
where T: Clone,

Implementors§