Kimundi / owning-ref-rs

A library for creating references that carry their owner with them.
MIT License
359 stars 50 forks source link

There should be some intro in the documentation explaining why OwningRef is needed #4

Open vi opened 8 years ago

vi commented 8 years ago

My reactions when reading the doc:

This crate provides the owning reference type OwningRef that enables it to bundle a reference together with the owner of the data it points to.

Strange idea... Why not just use usual reference or the object itself?

This allows moving and dropping of a OwningRef without needing to recreate the reference.

What does mean to re-creating a reference? Can there be only one OwningRef to given object? Is it Rc, but for references?


Maybe there should be some easy introduction and rationale. There may also be a "nonworking" example where we can't do something, neither with usual references nor the object itself (showing partial source code with unfilled "impossible" line), but can with OwningRef (showing corrected, now working source code).

Is OwningRef to provide a limited "view" into subset of the object while preserving ownership? In that case there may be special example showing how OwningRef simplifies API like this:

fn print_sum_and_drop_array(data: Box<[u32]>, from: usize, len: usize);
fn print_sum_and_drop_array(x : BoxRef<[u32]>);
Kimundi commented 7 years ago

Hi, I'm sincerely sorry for taking so long to respond.

I've added a section in the docs about a motivating example of normal Rust code that would not compile and where this library could help, it is included in the next release.

Writing up more detailed use case scenarios sounds like a good idea too, but I did not get to that right now.