amethyst / amethyst/legion

`Entity::clone()` may return values different from `Copy`

Aperta
#248 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Rust
Stelle
1.7k
Fork
140
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

[This code](https://github.com/amethyst/legion/blob/0d0a53953465ca73e6f9231ecbae9044bf4b4389/src/internals/entity.rs#L24-L31) either doesn't uphold [a sane `Clone` invariant](https://doc.rust-lang.org/std/clone/trait.Clone.html#how-can-i-implement-clone) or is totally useless for anything but internal use.

So, there are two possible problems:

1. Using `ent.clone()` could give the user a value different from `*ent`. This is kinda awful, because `sane_logic` function would panic:

```rust
fn sane_logic(t: &T) {
assert_eq!(t.clone(), *t);
}
```

2. Using `ent.clone()` could not give the user a value different from `*ent`. This is not as bad as the first problem, but every time the user calls `clone()` instead of making a copy, he would spend time accessing thread-local hashmap inside the `RefCell`. May slow some things generic over `Clone` instead of `Copy`, like `iter.cloned()` instead of `iter.map(|x| *x)`.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.