Open ghost opened 3 years ago
Distinguishing Unique
is probably still useful for free
and queue_free
, but the Deref
implementation should be removed. It should only be possible to create TRef
s for Shared
references.
I wonder if ThreadLocal
can be preserved since user code outside Rust is assumed to follow the threading guidelines as part of the safety model? If so then it's only Unique
that is the most fragile.
As long as API method calls are allowed on references with typestates, their invariants cannot be soundly upheld without manual review.
Suppose that there is a method
Node::add_as_child_to(other: Node)
that addsthis
as a child toother
. If such a method is called on a reference withUnique
access, the access state is invalidated. There is no way we can identify such methods should they exist in the API without manual review of engine code (or at least documentation).As such,
Deref
should not be implemented for theUnique
typestate. Functions that create new instances should returnShared
instead (and require aassume_safe
call afterwards).