13 unstable releases (6 breaking)

0.6.2 Sep 27, 2022
0.6.0 Jun 1, 2022
0.4.0 Jan 31, 2022
0.3.1 Nov 1, 2021
0.2.3 Jul 29, 2021

#23 in Memory management

Download history 2443/week @ 2022-08-15 2104/week @ 2022-08-22 2716/week @ 2022-08-29 3576/week @ 2022-09-05 3792/week @ 2022-09-12 4360/week @ 2022-09-19 4405/week @ 2022-09-26 3410/week @ 2022-10-03 3862/week @ 2022-10-10 4250/week @ 2022-10-17 4624/week @ 2022-10-24 4290/week @ 2022-10-31 4247/week @ 2022-11-07 6774/week @ 2022-11-14 9424/week @ 2022-11-21 9096/week @ 2022-11-28

29,664 downloads per month
Used in 44 crates (12 directly)

Unicode-DFS-2016

96KB
892 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()][Yoke::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

~190KB