Skip to content

A library for creating references that carry their owner with them.

License

Notifications You must be signed in to change notification settings

xmas7/owning-ref-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

owning-ref-rs

Travis-CI Status

A library for creating references that carry their owner with them.

For more details, see the docs.

Getting Started

owning-ref-rs is available on crates.io. 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

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]);
}

About

A library for creating references that carry their owner with them.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages