| { | ||
| "git": { | ||
| "sha1": "bb50cc9a00cbde008e6a8ef98655cf9b05e6dd6b" | ||
| "sha1": "7a471b7e4584bfc165d9e593295742c880369bf7" | ||
| }, | ||
| "path_in_vcs": "utils/yoke" | ||
| } |
+1
-1
@@ -15,3 +15,3 @@ # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO | ||
| name = "yoke" | ||
| version = "0.6.1" | ||
| version = "0.6.2" | ||
| authors = ["Manish Goregaokar <manishsmail@gmail.com>"] | ||
@@ -18,0 +18,0 @@ include = [ |
+1
-0
@@ -50,2 +50,3 @@ // This file is part of ICU4X. For terms of use, please see the file | ||
| #[derive(Clone, PartialEq, Eq)] | ||
| #[allow(clippy::exhaustive_enums)] // stable | ||
| pub enum EitherCart<C0, C1> { | ||
@@ -52,0 +53,0 @@ A(C0), |
+7
-0
@@ -14,2 +14,3 @@ // This file is part of ICU4X. For terms of use, please see the file | ||
| use alloc::rc::Rc; | ||
| use alloc::sync::Arc; | ||
@@ -24,2 +25,8 @@ /// Dummy trait that lets us `dyn Drop` | ||
| /// A type-erased Cart that has `Arc` semantics | ||
| /// | ||
| /// See the docs of [`Yoke::erase_arc_cart()`](crate::Yoke::erase_rc_cart) for more info. | ||
| /// | ||
| /// Available with the `"alloc"` feature enabled. | ||
| pub type ErasedArcCart = Arc<dyn ErasedDestructor + Send + Sync>; | ||
| /// A type-erased Cart that has `Rc` semantics | ||
@@ -26,0 +33,0 @@ /// |
+2
-2
@@ -36,4 +36,4 @@ // This file is part of ICU4X. For terms of use, please see the file | ||
| clippy::panic, | ||
| // TODO(#1668): enable clippy::exhaustive_structs, | ||
| // TODO(#1668): enable clippy::exhaustive_enums, | ||
| clippy::exhaustive_structs, | ||
| clippy::exhaustive_enums, | ||
| // TODO(#2266): enable missing_debug_implementations, | ||
@@ -40,0 +40,0 @@ ) |
@@ -289,2 +289,3 @@ // This file is part of ICU4X. For terms of use, please see the file | ||
| #[derive(Clone, PartialEq, Eq)] | ||
| #[allow(clippy::exhaustive_structs)] // newtype | ||
| pub struct YokeTraitHack<T>(pub T); | ||
@@ -291,0 +292,0 @@ |
+57
-1
@@ -7,3 +7,3 @@ // This file is part of ICU4X. For terms of use, please see the file | ||
| #[cfg(feature = "alloc")] | ||
| use crate::erased::{ErasedBoxCart, ErasedRcCart}; | ||
| use crate::erased::{ErasedArcCart, ErasedBoxCart, ErasedRcCart}; | ||
| use crate::trait_hack::YokeTraitHack; | ||
@@ -886,2 +886,46 @@ use crate::IsCovariant; | ||
| #[cfg(feature = "alloc")] | ||
| impl<Y: for<'a> Yokeable<'a>, C: 'static + Sized + Send + Sync> Yoke<Y, Arc<C>> { | ||
| /// Allows type-erasing the cart in a `Yoke<Y, Arc<C>>`. | ||
| /// | ||
| /// The yoke only carries around a cart type `C` for its destructor, | ||
| /// since it needs to be able to guarantee that its internal references | ||
| /// are valid for the lifetime of the Yoke. As such, the actual type of the | ||
| /// Cart is not very useful unless you wish to extract data out of it | ||
| /// via [`Yoke::backing_cart()`]. Erasing the cart allows for one to mix | ||
| /// [`Yoke`]s obtained from different sources. | ||
| /// | ||
| /// In case the cart type `C` is not already an `Arc<T>`, you can use | ||
| /// [`Yoke::wrap_cart_in_arc()`] to wrap it. | ||
| /// | ||
| /// # Example | ||
| /// | ||
| /// ```rust | ||
| /// use std::sync::Arc; | ||
| /// use yoke::erased::ErasedArcCart; | ||
| /// use yoke::Yoke; | ||
| /// | ||
| /// let buffer1: Arc<String> = Arc::new(" foo bar baz ".into()); | ||
| /// let buffer2: Box<String> = Box::new(" baz quux ".into()); | ||
| /// | ||
| /// let yoke1 = Yoke::<&'static str, _>::attach_to_cart(buffer1, |arc| arc.trim()); | ||
| /// let yoke2 = Yoke::<&'static str, _>::attach_to_cart(buffer2, |b| b.trim()); | ||
| /// | ||
| /// let erased1: Yoke<_, ErasedArcCart> = yoke1.erase_arc_cart(); | ||
| /// // Wrap the Box in an Rc to make it compatible | ||
| /// let erased2: Yoke<_, ErasedArcCart> = yoke2.wrap_cart_in_arc().erase_arc_cart(); | ||
| /// | ||
| /// // Now erased1 and erased2 have the same type! | ||
| /// ``` | ||
| /// | ||
| /// Available with the `"alloc"` feature enabled. | ||
| pub fn erase_arc_cart(self) -> Yoke<Y, ErasedArcCart> { | ||
| unsafe { | ||
| // safe because the cart is preserved, just | ||
| // type-erased | ||
| self.replace_cart(|c| c as ErasedArcCart) | ||
| } | ||
| } | ||
| } | ||
| #[cfg(feature = "alloc")] | ||
| impl<Y: for<'a> Yokeable<'a>, C: 'static + Sized> Yoke<Y, Box<C>> { | ||
@@ -955,2 +999,14 @@ /// Allows type-erasing the cart in a `Yoke<Y, Box<C>>`. | ||
| } | ||
| /// Helper function allowing one to wrap the cart type `C` in an `Rc<T>`. | ||
| /// Can be paired with [`Yoke::erase_arc_cart()`], or generally used | ||
| /// to make the [`Yoke`] cloneable. | ||
| /// | ||
| /// Available with the `"alloc"` feature enabled. | ||
| #[inline] | ||
| pub fn wrap_cart_in_arc(self) -> Yoke<Y, Arc<C>> { | ||
| unsafe { | ||
| // safe because the cart is preserved, just wrapped | ||
| self.replace_cart(Arc::new) | ||
| } | ||
| } | ||
| } | ||
@@ -957,0 +1013,0 @@ |
Sorry, the diff of this file is not supported yet