Skip to content

Commit

Permalink
Implement todos; remove unused new yoke function
Browse files Browse the repository at this point in the history
  • Loading branch information
sffc committed Dec 13, 2023
1 parent bd594ab commit 3215f0a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
17 changes: 15 additions & 2 deletions provider/core/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,14 @@ impl Cart {
for<'a> Y: Yokeable<'a>,
F: FnOnce(&[u8]) -> Result<<Y as Yokeable>::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<Y, Cart>` from an infallible fn.
Expand All @@ -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(),
})
}
}
}

Expand Down
15 changes: 0 additions & 15 deletions utils/yoke/src/yoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,21 +511,6 @@ impl<Y: for<'a> Yokeable<'a>, C: StableDeref> Yoke<Y, Option<C>> {
}
}

/// Converts `Yoke<Y, Option<C>>` to `Yoke<Y, C>`, 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<Y, C> {
match self.cart {
Some(cart) => Yoke {
yokeable: self.yokeable,
cart,
},
None => Yoke {
yokeable: self.yokeable,
cart: f(),
},
}
}

/// Obtain the yokeable out of a `Yoke<Y, Option<C>>` if possible.
///
/// If the cart is `None`, this returns `Some`, but if the cart is `Some`,
Expand Down

0 comments on commit 3215f0a

Please sign in to comment.