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
**This Commit**
Adds history to the functional BST and no longer requires ownership to
`insert`/`delete`.
**Why?**
Mainly to make benchmarking easier but this has the benefit of more
closely matching a functional data structure in that, when new trees are
created from "mutating" operations, the history of trees/operations is
still accessible.
Use struct update syntax for conciseness
**Why?**
I didn't think I could do this but the issue was that I had `derive`d
`Clone` on `Node` when I should've implemented it directly because it's
generic and leverages reference counting.
See #6 (comment)
Explicitly clone needed fields of nodes
**This Commit**
Removes instances of instantiating new `Node`s using the functional
update syntax of a clone of an existing `Node`. That is it replaces:
```rust
Node {
some_field: some_value,
..existing_node.clone()
}
```
with
```rust
Node {
some_field: some_value,
other_field: existing_node.other_field.clone(),
// etc.
}
```
**Why?**
For clarity - when using `..node.clone()` what's
happening is we are first cloning the node in its entirety (which
results in bumping the reference count for all its fields), moving the
fields we care about to the new `Node`, and then dropping the remaining
fields (and decrementing their reference count). This is a surprise to
the reader and is needless and not what we want to express. It also may
have a performance impact but that isn't measured.
For more details see [this comment thread][0].
[0]: #6 (comment)
Deny `clippy::clone_on_ref_ptr`
**This Commit**
Denies the use of `.clone()` on reference counted pointers as advised by
[this `clippy` lint][0] and [The Rust Book][1]. It also addresses
instances where the lint was violated.
**Why?**
It's best practice to make clear the clone is cheap. There is [some
debate][2] on the issue and the [standard library no longer explicitly
recommends it][3] but it is still noted as more idiomatic.
In any case, for us there are no issues making the change and if there
is a possibility for being more expressive, we should take it.
See #6 (comment)
for more details.
[0]: https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_ref_ptr
[1]: https://doc.rust-lang.org/book/ch15-04-rc.html#using-rct-to-share-data
[2]: rust-lang/rust-clippy#2048
[3]: rust-lang/rust#76138
0 commit comments