This repository was archived by the owner on Oct 14, 2021. It is now read-only.
Value::iter without collecting into a Vec #129
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There are two subtleties in this PR.
First, Rust standard library has no
RefVal
object whichcontains not a reference like
Ref
but a value bound toRefVal
lifetime. Seems like it is not possible to implement
RefVal
safely in current Rust.
Since it's not possible to return anything except references inside
RefCell
, returned value is "iterable", not "iterator" (simplydowncast
TypedValue
).It's not possible to implement
IntoIterator
forRef
, soIntoIterator
is implemented for&Ref
(&RefIterable
).Thus iteration over value returned by
Value::iter
now looks like this:And if an iterator is needed explicitly, iterable need to be stored
in a temporary variable.
Second, mutability flag is hidden inside
TypedValue
, so toquery mutability we need to borrow
TypedValue
first. But we needto check mutability before invoking mutating operations.
So
Value
has now magicborrow_mut_check_mutability
function,which borrows immutably after
borrow_mut
failed to return propererror.