Crates.io | atomicow |
lib.rs | atomicow |
version | 1.0.0 |
source | src |
created_at | 2024-08-29 20:11:36.193025 |
updated_at | 2024-08-29 20:11:36.193025 |
description | A `Cow`-like data structure where owned data is stored inside an `Arc`. |
homepage | |
repository | https://github.com/bevyengine/atomicow |
max_upload_size | |
id | 1356703 |
size | 22,906 |
atomicow
A Cow
-like data structure where owned data is stored inside an Arc
.
Here's what it looks like:
pub enum CowArc<'a, T: ?Sized + 'static> {
Borrowed(&'a T),
Static(&'static T),
Owned(Arc<T>),
}
As implied by the Cow
name, this type allows for cheap immutable reference, but can be converted into an owned form via cloning when mutation or ownership is required.
This data structure is particularly useful for str
or other values with a static lifetime,
as might be used in structures such as asset paths.
A 'static str
stored in a CowArc
can be cloned without allocations or bookkeeping,
while owned values are shared by reference-counting in a thread-safe fashion.
cow_arc
crateThe similar cow_arc
crate already exists.
How does atomicow
differ?
Put simply: cow_arc
's data structure is just a wrapper over an Arc
.
While this is exactly what you need in some use cases,
the enum structure used in atomicow
is both more transparent and more flexible.
This crate is maintained by the Bevy organization, and is intended to be tiny, stable, zero-dependency, and broadly useful. Issues and pull requests are genuinely welcome!