https://github.com/xmas7/owning-ref-rs
A library for creating references that carry their owner with them.
https://github.com/xmas7/owning-ref-rs
library own ref rust
Last synced: over 1 year ago
JSON representation
A library for creating references that carry their owner with them.
- Host: GitHub
- URL: https://github.com/xmas7/owning-ref-rs
- Owner: xmas7
- License: mit
- Created: 2022-09-06T00:01:21.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2022-09-06T00:03:57.000Z (almost 4 years ago)
- Last Synced: 2025-02-01T09:27:57.792Z (over 1 year ago)
- Topics: library, own, ref, rust
- Language: Rust
- Homepage:
- Size: 8.79 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
owning-ref-rs
==============
[](https://travis-ci.org/Kimundi/owning-ref-rs)
A library for creating references that carry their owner with them.
For more details, see the [docs](http://kimundi.github.io/owning-ref-rs/owning_ref/index.html).
# Getting Started
[owning-ref-rs is available on crates.io](https://crates.io/crates/owning_ref).
Add the following dependency to your Cargo manifest to get the latest version of the 0.1 branch:
```
[dependencies]
owning_ref = "0.1.*"
```
To always get the latest version, add this git repository to your
Cargo manifest:
```
[dependencies.owning_ref]
git = "https://github.com/Kimundi/owning-ref-rs"
```
# Example
```rust
extern crate owning_ref;
use owning_ref::RcRef;
fn main() {
// Let's create a few reference counted slices that point to the same memory:
let rc: RcRef<[i32]> = RcRef::new(Rc::new([1, 2, 3, 4]) as Rc<[i32]>);
assert_eq!(&*rc, &[1, 2, 3, 4]);
let rc_a: RcRef<[i32]> = rc.clone().map(|s| &s[0..2]);
let rc_b = rc.clone().map(|s| &s[1..3]);
let rc_c = rc.clone().map(|s| &s[2..4]);
assert_eq!(&*rc_a, &[1, 2]);
assert_eq!(&*rc_b, &[2, 3]);
assert_eq!(&*rc_c, &[3, 4]);
}
```