Skip to content

ArcBorrow #7

Description

@Tamschi

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 if T isn'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 an Arc<T>.

Describe the solution you'd like

ArcBorrow<T> must be Deref<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> and
  • fn 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 triomphe has, 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    domain: RustInvolves Rust code.good first issueGood for newcomerstype: featureBrand new functionality, features, pages, workflows, endpoints, etc.work: clearA known solution is (to be) implemented.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions