18 releases

0.7.4 May 28, 2024
0.7.3 Nov 16, 2023
0.7.2 Sep 22, 2023
0.7.1 Apr 13, 2023
0.2.3 Jul 29, 2021

#11 in Memory management

Download history 102023/week @ 2024-07-30 117738/week @ 2024-08-06 108627/week @ 2024-08-13 106450/week @ 2024-08-20 108441/week @ 2024-08-27 126315/week @ 2024-09-03 117595/week @ 2024-09-10 132837/week @ 2024-09-17 166641/week @ 2024-09-24 174285/week @ 2024-10-01 171548/week @ 2024-10-08 170325/week @ 2024-10-15 161828/week @ 2024-10-22 223448/week @ 2024-10-29 785161/week @ 2024-11-05 912047/week @ 2024-11-12

2,116,851 downloads per month
Used in 27,952 crates (28 directly)

Unicode-3.0

125KB
1K SLoC

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.

Dependencies

~180KB