TRAITS: Largest: refactor to not need Copy trait
Return reference to list element
This commit is contained in:
parent
4ed58084c2
commit
c091a91f2a
1 changed files with 3 additions and 3 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
fn largest<T: PartialOrd + Copy>(list: &[T]) -> T {
|
fn largest<T: PartialOrd>(list: &[T]) -> &T {
|
||||||
let mut largest = list[0];
|
let mut largest = &list[0];
|
||||||
|
|
||||||
for &item in list {
|
for item in list {
|
||||||
if item > largest {
|
if item > largest {
|
||||||
largest = item;
|
largest = item;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue