| 1 |
// This file is part of ICU4X. For terms of use, please see the file |
| 2 |
// called LICENSE at the top level of the ICU4X source tree |
| 3 |
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). |
| 4 |
|
| 5 |
//! This module contains helper types for erasing Cart types. |
| 6 |
//! |
| 7 |
//! See the docs of [`Yoke::erase_rc_cart()`](crate::Yoke::erase_rc_cart) |
| 8 |
//! and [`Yoke::erase_box_cart()`](crate::Yoke::erase_box_cart) for more info. |
| 9 |
//! |
| 10 |
//! ✨ *Enabled with the `alloc` Cargo feature.* |
| 11 |
|
| 12 |
use alloc::boxed::Box; |
| 13 |
use alloc::rc::Rc; |
| 14 |
use alloc::sync::Arc; |
| 15 |
|
| 16 |
/// Dummy trait that lets us `dyn Drop` |
| 17 |
/// |
| 18 |
/// `dyn Drop` isn't legal (and doesn't make sense since `Drop` is not |
| 19 |
/// implement on all destructible types). However, all trait objects come with |
| 20 |
/// a destructor, so we can just use an empty trait to get a destructor object. |
| 21 |
pub trait ErasedDestructor: 'static {} |
| 22 |
impl<T: 'static> ErasedDestructor for T {} |
| 23 |
|
| 24 |
/// A type-erased Cart that has `Arc` semantics |
| 25 |
/// |
| 26 |
/// See the docs of [`Yoke::erase_arc_cart()`](crate::Yoke::erase_rc_cart) for more info. |
| 27 |
/// |
| 28 |
/// ✨ *Enabled with the `alloc` Cargo feature.* |
| 29 |
pub type ErasedArcCart = Arc<dyn ErasedDestructor + Send + Sync>; |
| 30 |
/// A type-erased Cart that has `Rc` semantics |
| 31 |
/// |
| 32 |
/// See the docs of [`Yoke::erase_rc_cart()`](crate::Yoke::erase_rc_cart) for more info. |
| 33 |
/// |
| 34 |
/// ✨ *Enabled with the `alloc` Cargo feature.* |
| 35 |
pub type ErasedRcCart = Rc<dyn ErasedDestructor>; |
| 36 |
/// A type-erased Cart that has `Box` semantics |
| 37 |
/// |
| 38 |
/// See the docs of [`Yoke::erase_box_cart()`](crate::Yoke::erase_box_cart) for more info. |
| 39 |
/// |
| 40 |
/// ✨ *Enabled with the `alloc` Cargo feature.* |
| 41 |
pub type ErasedBoxCart = Box<dyn ErasedDestructor>; |