dioxus icon indicating copy to clipboard operation
dioxus copied to clipboard

Use owning_ref to remove need for calling .read and .write on signals

Open vultix opened this issue 1 year ago • 1 comments

Feature Request

I believe it should be possible using the owning-ref crate to directly implement Deref and DerefMut for Signal, allowing code like signal.mutate() instead of signal.write().mutate()

This will be a huge ergonomic win if we can get it to work!

vultix avatar Mar 29 '24 14:03 vultix

I'm not familiar with OwningRef, but rust has a limitation that makes it impossible to both implement Copy and Drop at the same time. To safely implement Deref, Refs need to hold a lock that prevents other RefMuts from accessing the data at the same time. To release that lock when you are done using the Ref, you need to implement Drop.

Because of this I don't think it is possible to implement both Copy and Deref on Signal. (RefRef in the OwningRef crate implements Drop so it cannot implement Copy)

ealmloff avatar Mar 29 '24 17:03 ealmloff

Ah, you're spot on. If we ever get something akin to super let it should be possible to implement something like this, but for now this seems impossible.

vultix avatar May 10 '24 16:05 vultix