-
-
Notifications
You must be signed in to change notification settings - Fork 0
ArcBorrow #7
Copy link
Copy link
Open
Labels
domain: RustInvolves Rust code.Involves Rust code.good first issueGood for newcomersGood for newcomerstype: featureBrand new functionality, features, pages, workflows, endpoints, etc.Brand new functionality, features, pages, workflows, endpoints, etc.work: clearA known solution is (to be) implemented.A known solution is (to be) implemented.
Description
Activity
Metadata
Metadata
Assignees
Labels
domain: RustInvolves Rust code.Involves Rust code.good first issueGood for newcomersGood for newcomerstype: featureBrand new functionality, features, pages, workflows, endpoints, etc.Brand new functionality, features, pages, workflows, endpoints, etc.work: clearA known solution is (to be) implemented.A known solution is (to be) implemented.
Is your feature request related to a problem? Please describe.
While some APIs can be constrained to allow cloning
Pin<Arc<T>>from&T, this isn't universally true and especially won't work ifTisn't pinned. However, it's still possible to efficiently borrow the value with a newtype that remembers its status:struct ArcBorrow<'a, T>(&'a T), where the reference is guaranteed to point inside anArc<T>.Describe the solution you'd like
ArcBorrow<T>must beDeref<T>and so on. It should overall behave like the plain reference would.There should only be two exposed associated functions:
fn clone_arc(this: Self) -> Arc<T>andfn clone_pin(this: Pin<Self>) -> Pin<Arc<T>>Describe alternatives you've considered
None, though the type name is somewhat up in the air.
Additional context
This is essentially the same API that
triomphehas, which in part inspired this crate.It's slightly more convenient to implement it with an intrusive counter, but otherwise should behave just about the same.