diff --git a/provider/core/src/response.rs b/provider/core/src/response.rs index f4c4c1bb145..20dbb776933 100644 --- a/provider/core/src/response.rs +++ b/provider/core/src/response.rs @@ -89,7 +89,14 @@ impl Cart { for<'a> Y: Yokeable<'a>, F: FnOnce(&[u8]) -> Result<::Output, E>, { - todo!() + Yoke::try_attach_to_cart(SelectedRc::new(cart), |b| f(b)) + // Safe because the cart is only wrapped + .map(|yoke| unsafe { + yoke.replace_cart(|selected_rc| { + Cart(OptionSelectedRcBytes::from_selected_rc(selected_rc)) + }) + }) + .map(Yoke::wrap_cart_in_option) } /// Creates a `Yoke` from an infallible fn. @@ -111,7 +118,13 @@ impl Cart { where for<'a> Y: Yokeable<'a>, { - todo!() + // Safe because the cart is only unwrapped + unsafe { + yoke.replace_cart(|option_cart| match option_cart { + Some(cart) => cart, + None => empty_cart(), + }) + } } } diff --git a/utils/yoke/src/yoke.rs b/utils/yoke/src/yoke.rs index 4b0cf5ee993..0826ffc2e56 100644 --- a/utils/yoke/src/yoke.rs +++ b/utils/yoke/src/yoke.rs @@ -511,21 +511,6 @@ impl Yokeable<'a>, C: StableDeref> Yoke> { } } - /// Converts `Yoke>` to `Yoke`, replacing the `None` - /// cart with the value returned by the given function (a sentinel). - pub fn unwrap_cart_or_else(self, f: impl FnOnce() -> C) -> Yoke { - match self.cart { - Some(cart) => Yoke { - yokeable: self.yokeable, - cart, - }, - None => Yoke { - yokeable: self.yokeable, - cart: f(), - }, - } - } - /// Obtain the yokeable out of a `Yoke>` if possible. /// /// If the cart is `None`, this returns `Some`, but if the cart is `Some`,