Sunbeam Studios

Our open-source projects, here for you!

yoke (0.8.1)

Published 2026-03-26 10:37:08 +00:00 by siennathesane

Installation

[registry]
default = "gitea"

[registries.gitea]
index = "sparse+" # Sparse index
# index = "" # Git

[net]
git-fetch-with-cli = true
cargo add yoke@0.8.1

About this package

Abstraction allowing borrowed data to be carried along with the backing data it borrows from

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

ID Version
stable_deref_trait ^1.2.0
yoke-derive ^0.8.0
zerofrom ^0.1.3
bincode ^1.3.1
postcard ^1.0.3
serde ^1.0.220

Keywords

zerocopy serialization lifetime borrow self-referential
Details
Cargo
2026-03-26 10:37:08 +00:00
0
Manish Goregaokar <manishsmail@gmail.com>
Unicode-3.0
31 KiB
Assets (1)
Versions (1) View all
0.8.1 2026-03-26