Re: [PATCH v7 4/4] rust: adding OwnableRefCounted and SimpleOwnableRefCounted
From: Oliver Mangold
Date: Wed Mar 12 2025 - 06:37:44 EST
On 250310 1047, Boqun Feng wrote:
> On Mon, Mar 10, 2025 at 10:57:47AM +0000, Oliver Mangold wrote:
> > +pub unsafe trait SimpleOwnableRefCounted {
>
> Can you make this trait as a sub-trait of RefCounted:
>
> pub unsafe trait SimpleOwnableRefCounted: RefCounted {
> fn is_unique(&self) -> bool;
> }
>
> ?
>
Good idea. Simplifies things. Will do that.
> > + /// Checks if exactly one [`ARef`] to the object exists. In case the object is [`Sync`], the
> > + /// check needs to be race-free.
> > + fn is_unique(&self) -> bool;
> > +
> > + /// Increments the reference count on the object.
> > + fn inc_ref(&self);
> > +
> > + /// Decrements the reference count on the object when the [`SimpleOwnableRefCounted`] is
>
> Should be:
>
> "... when ARef<SimpleOwnableRefCounted> or
> Owned<SimpleOwnableRefCounted> is dropped"
>
> ?
>
> > + /// dropped.
> > + ///
> > + /// Frees the object when the count reaches zero.
>
> It may not end up freeing the object, because ARef<..> only tracks the
> Rust side of refcounting, we should avoid mentioning "refcount reaching
> to zero" here.
>
This docu will vanish together with the functions, of course, after the change
above. One might note, though, that the last comment was a copy-paste from
AlwaysRefCounted (now RefCounted) where it still exists identically.
Best regards,
Oliver