Open xq-tec opened 3 years ago
So, to provide a little more context, Rust's Index
and IndexMut
traits are specifically intended for container types, in which the result of the index operation already exists, so that you can return a reference to it. In your implementation of Index
however, the result is created on the fly, so you can't return a reference to it. There are two solutions:
ValueNthElementValue()
computes this reference, but it copies the referenced value to another location instead of returning a pointer. You could reimplement ValueNthElementValue()
, but that would violate the Sciter source code license agreement, and the reimplementation would be susceptible to changes in the underlying data structure. So that's a no-go.Index
and IndexMut
implementations and replace their uses with get()
, set()
, get_item()
, and set_item()
.Yeah, I know that Rust doesn't support that and introducing the indexing via a hack was a bad idea. It's mentioned in #27.
There's a serious bug in the
sciter::value::Value
implementation related tostd::ops::Index
:This will print something like this, which is obviously incorrect:
The culprit is this code, which reuses the
tmp
field in a&self
method:This isn't just a bug, it's also straight up Undefined Behavior. The Clippy
mut_from_ref
lint is there for a reason...