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

stevenblenkinsop/owning-ref-rs

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 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::BoxRef;

fn main() {
    // Create an array owned by a Box.
    let arr = Box::new([1, 2, 3, 4]) as Box<[i32]>;

    // Transfer into a BoxRef.
    let arr: BoxRef<[i32]> = BoxRef::new(arr);
    assert_eq!(&*arr, &[1, 2, 3, 4]);

    // We can slice the array without losing ownership or changing type.
    let arr: BoxRef<[i32]> = arr.map(|arr| &arr[1..3]);
    assert_eq!(&*arr, &[2, 3]);

    // Also works for Arc, Rc, String and Vec!
}

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 100.0%