Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upUse RefCell to prevent multiple mutable references of current value #3
Comments
This comment has been minimized.
This comment has been minimized.
|
Reddit comment: #3 |
This comment has been minimized.
This comment has been minimized.
|
If we put an extra field in the hash table, then we can tell whether it is borrowed mutable or immutable. |
This comment has been minimized.
This comment has been minimized.
|
RefCell uses an uint with -1 as WRITING and 0 as UNUSED. The other values are used for immutable references. |
This comment has been minimized.
This comment has been minimized.
|
Perhaps best to use similar conventions as the standard library.
|
This comment has been minimized.
This comment has been minimized.
|
Suggestion for names: RefCurrent and RefMutCurrent
|
This comment has been minimized.
This comment has been minimized.
|
In order to avoid having to type "let foo: RefMutCurrent = Current::borrow_mut(scope)" we could do "let foo = Current::borrow_mut::::(scope);". |
This comment has been minimized.
This comment has been minimized.
|
Alternative is to use immutable references and use RefCell as convention for mutable ones. |
bvssvni
added
the
discussion
label
Nov 2, 2014
This comment has been minimized.
This comment has been minimized.
|
This will not be implemented in favor of using RefCell with immutable references. |
bvssvni commentedNov 2, 2014
As suggested on reddit, this enforces the safety at runtime and might be combined with the design such that the current value can only be borrowed once as mutable but multiple times as immutable.