https://github.com/bevyengine/atomicow
A `Cow`-like data structure where owned data is stored inside an `Arc`.
https://github.com/bevyengine/atomicow
Last synced: 3 months ago
JSON representation
A `Cow`-like data structure where owned data is stored inside an `Arc`.
- Host: GitHub
- URL: https://github.com/bevyengine/atomicow
- Owner: bevyengine
- License: apache-2.0
- Created: 2024-08-26T20:12:30.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-03-21T04:25:55.000Z (3 months ago)
- Last Synced: 2025-03-29T21:02:57.120Z (3 months ago)
- Language: Rust
- Size: 34.2 KB
- Stars: 29
- Watchers: 3
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# `atomicow`

[](https://crates.io/crates/atomicow)
[](https://crates.io/crates/atomicow)
[](https://docs.rs/atomicow/latest/atomicow/)A [`Cow`](https://doc.rust-lang.org/std/borrow/enum.Cow.html)-like data structure where owned data is stored inside an [`Arc`](https://doc.rust-lang.org/std/sync/struct.Arc.html).
Here's what it looks like:```rust, ignore
pub enum CowArc<'a, T: ?Sized + 'static> {
Borrowed(&'a T),
Static(&'static T),
Owned(Arc),
}
```As implied by the `Cow` name, this type allows for cheap immutable reference, but can be converted into a shared owned form via cloning when lifetime extension 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.## Comparison to the `cow_arc` crate
The similar [`cow_arc`](https://docs.rs/cow_arc/latest/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.## Contributing
This crate is maintained by the Bevy organization, and is intended to be tiny, stable, zero-dependency, and broadly useful.
[Issues](https://github.com/bevyengine/atomicow/issues) and [pull requests](https://github.com/bevyengine/atomicow/pulls) are genuinely welcome!