The semantics of something like Handle does add a lot of clarity for me. I had just written an app using tokio and arc and the clones always felt off.
Why not just expand meaning of
&
?let l_before = &v1;
How do I now actually get a &Arc? Without implicitly cloning?
& is such a fundamental part of the syntax, I really don’t think it’s meaning should be muddled.
What’s the use-case for &Arc? Modifying an Arc object in outer scope?
To me, this handle trait sounds a lot like “reference-counted reference”. When there already exists a pure “reference” in the language
I don’t know but it could be anything else than an Arc. Obviously you should still be able to take a usual reference to such a thing.
References are just pointers, they don’t have any counting. This proposal as I understand it is an attempt at making reference-counting more ergonomic.
I don’t know but it could be anything else than an Arc. Obviously you should still be able to take a usual reference to such a thing.
Maybe. My point is that unless you want to, for example, have a reference that you switch between which object it references, I think you would be fine with using the ref-counted reference. With eventual optimization done via compiler when it’s sure the code won’t be trying to access the object after it got deleted. But even if I’m wrong, there could be another way to get a pure reference
This proposal as I understand it is an attempt at making reference-counting more ergonomic.
Yes, and IMO by using
Handle
for that it breaks a pattern. Rust keeps*
and&
for speaking about values and memory management (I want data vs I want reference). Using a trait for ref-counted referencing adds another layer. So suddenly we have*
,&
and::Handle()
. You see what I’m getting at?
Without ref counting it is hard to know when to free or safely change a value with multiple consumers
I mean, keep the ref-counting. Just from the syntax perspective. Aligning with the example in the post: & before Arc would increment reference count, before a Mutex would reference the same object as it does now