diff --git a/utils/yoke/src/yoke.rs b/utils/yoke/src/yoke.rs index 7dca0f89cb7..1432baaca38 100644 --- a/utils/yoke/src/yoke.rs +++ b/utils/yoke/src/yoke.rs @@ -88,9 +88,35 @@ impl Yokeable<'a>, C: StableDeref> Yoke { /// /// See also [`Yoke::try_attach_to_cart()`] to return a `Result` from the closure. /// - /// Due to [compiler bug #84937](https://github.com/rust-lang/rust/issues/84937), call sites - /// for this function may not compile; if this happens, use + /// Call sites for this function may not compile; if this happens, use /// [`Yoke::attach_to_cart_badly()`] instead. + /// + /// # Examples + /// + /// The following code does not currently compile. + /// See [#1061](https://github.com/unicode-org/icu4x/issues/1061). + /// + /// ```compile_fail + /// # use yoke::{Yoke, Yokeable}; + /// # use std::rc::Rc; + /// # use std::borrow::Cow; + /// # fn load_from_cache(_filename: &str) -> Rc<[u8]> { + /// # // dummy implementation + /// # Rc::new([0x5, 0, 0, 0, 0, 0, 0, 0, 0x68, 0x65, 0x6c, 0x6c, 0x6f]) + /// # } + /// + /// fn load_object(filename: &str) -> Yoke, Rc<[u8]>> { + /// let rc: Rc<[u8]> = load_from_cache(filename); + /// Yoke::, Rc<[u8]>>::attach_to_cart(rc, |data: &[u8]| { + /// // essentially forcing a #[serde(borrow)] + /// Cow::Borrowed(bincode::deserialize(data).unwrap()) + /// }) + /// } + /// + /// let yoke: Yoke, _> = load_object("filename.bincode"); + /// assert_eq!(&**yoke.get(), "hello"); + /// assert!(matches!(yoke.get(), &Cow::Borrowed(_))); + /// ``` pub fn attach_to_cart(cart: C, f: F) -> Self where F: for<'de> FnOnce(&'de ::Target) -> >::Output, @@ -105,9 +131,9 @@ impl Yokeable<'a>, C: StableDeref> Yoke { /// Construct a [`Yoke`] by yokeing an object to a cart. If an error occurs in the /// deserializer function, the error is passed up to the caller. /// - /// Due to [compiler bug #84937](https://github.com/rust-lang/rust/issues/84937), call sites - /// for this function may not compile; if this happens, use + /// Call sites for this function may not compile; if this happens, use /// [`Yoke::try_attach_to_cart_badly()`] instead. + /// See [#1061](https://github.com/unicode-org/icu4x/issues/1061). pub fn try_attach_to_cart(cart: C, f: F) -> Result where F: for<'de> FnOnce(&'de ::Target) -> Result<>::Output, E>, @@ -584,11 +610,8 @@ impl Yokeable<'a>, C> Yoke { /// described in [#86702](https://github.com/rust-lang/rust/issues/86702). This parameter /// should just be ignored in the function. /// - /// Furthermore, - /// [compiler bug #84937](https://github.com/rust-lang/rust/issues/84937) prevents - /// this from taking a capturing closure, however [`Yoke::project_with_capture()`] - /// can be used for the same use cases. - /// + /// To capture data and pass it to the closure, use [`Yoke::project_with_capture()`]. + /// See [#1061](https://github.com/unicode-org/icu4x/issues/1061). /// /// This can be used, for example, to transform data from one format to another: /// @@ -688,9 +711,9 @@ impl Yokeable<'a>, C> Yoke { } } - /// This is similar to [`Yoke::project`], however it works around it not being able to - /// use `FnOnce` by using an explicit capture input, until [compiler bug #84937](https://github.com/rust-lang/rust/issues/84937) - /// is fixed. + /// This is similar to [`Yoke::project`], but it works around it not being able to + /// use `FnOnce` by using an explicit capture input. + /// See [#1061](https://github.com/unicode-org/icu4x/issues/1061). /// /// See the docs of [`Yoke::project`] for how this works. pub fn project_with_capture( @@ -713,8 +736,8 @@ impl Yokeable<'a>, C> Yoke { } /// This is similar to [`Yoke::project_cloned`], however it works around it not being able to - /// use `FnOnce` by using an explicit capture input, until [compiler bug #84937](https://github.com/rust-lang/rust/issues/84937) - /// is fixed. + /// use `FnOnce` by using an explicit capture input. + /// See [#1061](https://github.com/unicode-org/icu4x/issues/1061). /// /// See the docs of [`Yoke::project_cloned`] for how this works. pub fn project_cloned_with_capture<'this, P, T>(