# cloned-instead-of-copied

Prefer copying iterator elements whose type is Copy

Calling `cloned` on Copy iterator elements permits custom cloning work when intrinsic duplication is sufficient.
Instead, you SHOULD call `copied` to state the Copy requirement directly.

- Category: performance
- Level: warning
- Fix: automatic
- Scope: module

## Reported

```ds title="main.ds"
import { Iterator } from "destack:iter";

function copy(values: Iterator<&readonly int32>): int32[] {
    return values.cloned().toArray();
}
```

## Accepted

```ds title="main.ds"
import { Iterator } from "destack:iter";

function copy(values: Iterator<&readonly int32>): int32[] {
    return values.copied().toArray();
}
```

## Prior art

- [Clippy · cloned_instead_of_copied](https://rust-lang.github.io/rust-clippy/master/index.html#cloned_instead_of_copied)

[language/linter/src/rules/performance/cloned_instead_of_copied.rs:8](https://github.com/destack-sh/destack/blob/main/language/linter/src/rules/performance/cloned_instead_of_copied.rs#L8)
