Pared: A new crate for projected reference-counted pointers

This mimics the aliasing constructor of C++'s shared_ptr, but with a (hopefully) safe interface that doesn't let you store a reference to anything other than a reference that can be obtained from the original data.

It could be useful in situations where you only want to expose a part of an Arc or a Rc to some thread or a part of your code. Unlike general-purpose crates like yoke, this should be very simple to use.

I would greatly appreciate any code review, soundness bug reveals, and/or PRs.

Special thanks to @CAD97, @alice and @steffahn for answering on my previous posts as great information sources.

Can't test right now, but from a glance it looks like it might suffer from the same bug as `OwningRef::map` is unsound · Issue #71 · Kimundi/owning-ref-rs · GitHub

4 Likes

You're right, it does

I fixed it for 0.2.0 by requiring that T: 'static. It doesn't break any usage examples, and while it's more restrictive this way, it shouldn't be in the way of any intended usage for this.

Thank you for pointing this out, I didn't realize the missing lifetime bound on the return value of the closure. I tested it with references, but it didn't occur to me to check with references to references.

I'm moderately annoyed that I couldn't figure out how to bind the return type of FnOnce to the lifetime it's using in the reference, but this shouldn't be too bad either.

You got the 'static bound backwards in the from_rc and from_arc methods (the input type if U but you bounded T)

Also, you choose to bound both T and U in Parc::project, while in Prc::project you only bounded T.

2 Likes

:man_facepalming:

I accidentally deleted the tests that were supposed to catch those kinds of errors, and kept a duplicate there instead.

0.2.1 it is, at least I can say that API change is a bugfix

Thank you for these, I really appreciate it.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.