6 releases (breaking)
0.5.0 | Oct 31, 2023 |
---|---|
0.4.0 | Sep 19, 2023 |
0.3.0 | Sep 19, 2023 |
0.2.1 | Sep 18, 2023 |
0.1.0 | Sep 18, 2023 |
#2741 in Rust patterns
49 downloads per month
20KB
324 lines
LArc Library
LArc is a Rust crate that implements a flexible smart pointer, LArc
and LWeak
, capable of storing
either static or lifetime annotated references or reference-counted smart pointers (Arc
).
The LArc Library provides a smart pointer, LArc, capable of seamlessly handling both static and dynamically allocated data. This duality allows for efficient management of data and structures that may transition between static and dynamic states. Common use cases include managing configuration data, resources, and caching, where data can start as static and later become dynamically updated.
Usage
To use this library in your Rust project, simply add it as a dependency in your Cargo.toml
file:
[dependencies]
larc = "0.5.0"
Then, import and use the LArc
and LWeak
types as needed in your Rust code:
use std::sync::Arc;
use larc::{LArc, LWeak};
fn main() {
// Create an LArc with a static reference
let larc_static = LArc::from_static("Hello, I'm a static reference!");
// Create an LArc with an Arc reference
let larc_arc = LArc::from_arc(Arc::<str>::from("Hello, I'm an Arc reference!"));
// Downgrade LArc to LWeak
let lweak = LArc::downgrade(&larc_arc);
}
For more information on the usage and API, refer to the documentation.
Contributing
Contributions are welcome! If you have any suggestions, bug reports, or enhancements, feel free to open an issue or create a pull request.
Status
So far this crate is useable, missing features will be added on demand/PR.
Planned
- Add more
Arc
compatibilty, but leave out functions that makes little sense for our use-cases. - More tests and docs.
Testing
The test-suite is far from complete yet, eventually cargo-mutants should be used to get good coverage of all cases.
Note that by design 'make_static()' intentionally leaks memory. Thus test that leak memory are disabled under miri. (This should be feature gated with MIRIFLAGS=-Zmiri-ignore-leaks)