You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As I remember, dynamic variables have this weird Option<&T> type and all this UnsafeCell magic inside because I wanted to be able to safely place references inside them.
However, this is kind of an overkill for value types, especially simple ones, like bool. How about putting the actual value inside the variable while still providing scoped get() accessor and scoped assignment guards?
In this way we could get away from using Option and generally simplify the API. The users will still be able to explicitly use Option if they would like it. But they could also use some definite value as the default (e.g., false).
I believe that it won’t be possible to put references to local variables or heap inside as they must ’static:
But it seems a safe thing to do so there might we a way.
Also, if you do it in a straightforward manner by moving the old value into the guard, this will result in unnecessary moves when setting and restoring the values. On the other side, if you keep a reference to the local variable then you don’t actually need to move anything, but that’s an additional indirection in getting the value.
The text was updated successfully, but these errors were encountered:
As I remember, dynamic variables have this weird
Option<&T>
type and all this UnsafeCell magic inside because I wanted to be able to safely place references inside them.However, this is kind of an overkill for value types, especially simple ones, like
bool
. How about putting the actual value inside the variable while still providing scopedget()
accessor and scoped assignment guards?In this way we could get away from using Option and generally simplify the API. The users will still be able to explicitly use Option if they would like it. But they could also use some definite value as the default (e.g.,
false
).I believe that it won’t be possible to put references to local variables or heap inside as they must
’static
:But it seems a safe thing to do so there might we a way.
Also, if you do it in a straightforward manner by moving the old value into the guard, this will result in unnecessary moves when setting and restoring the values. On the other side, if you keep a reference to the local variable then you don’t actually need to move anything, but that’s an additional indirection in getting the value.
The text was updated successfully, but these errors were encountered: