17 releases

0.7.3 Nov 16, 2023
0.7.1 Apr 13, 2023
0.7.0 Jan 26, 2023
0.6.2 Sep 27, 2022
0.2.3 Jul 29, 2021

#13 in Memory management

Download history 18322/week @ 2023-08-14 18276/week @ 2023-08-21 19540/week @ 2023-08-28 18796/week @ 2023-09-04 18596/week @ 2023-09-11 21170/week @ 2023-09-18 23533/week @ 2023-09-25 20458/week @ 2023-10-02 20717/week @ 2023-10-09 22256/week @ 2023-10-16 23602/week @ 2023-10-23 22244/week @ 2023-10-30 22583/week @ 2023-11-06 22928/week @ 2023-11-13 24017/week @ 2023-11-20 22309/week @ 2023-11-27

93,962 downloads per month
Used in 112 crates (19 directly)

Custom license

944 lines

yoke crates.io

This crate provides [Yoke<Y, C>][Yoke], which allows one to "yoke" (attach) a zero-copy deserialized object (say, a Cow<'a, str>) to the source it was deserialized from, (say, an Rc<[u8]>), known in this crate as a "cart", producing a type that looks like Yoke<Cow<'static, str>, Rc<[u8]>> and can be moved around with impunity.

Succinctly, this allows one to "erase" static lifetimes and turn them into dynamic ones, similarly to how dyn allows one to "erase" static types and turn them into dynamic ones.

Most of the time the yokeable Y type will be some kind of zero-copy deserializable abstraction, potentially with an owned variant (like Cow, ZeroVec, or an aggregate containing such types), and the cart C will be some smart pointer like Box<T>, Rc<T>, or Arc<T>, potentially wrapped in an Option<T>.

The key behind this crate is [Yoke::get()], where calling .get() on a type like Yoke<Cow<'static, str>, _> will get you a short-lived &'a Cow<'a, str>, restricted to the lifetime of the borrow used during .get(). This is entirely safe since the Cow borrows from the cart type C, which cannot be interfered with as long as the Yoke is borrowed by .get(). .get() protects access by essentially reifying the erased lifetime to a safe local one when necessary.

See the documentation of Yoke for more details.

More Information

For more information on development, authorship, contributing etc. please visit ICU4X home page.