Skip to content

CH 10: 01-syntax: Missing example. #3718

@ch9xy

Description

@ch9xy

URL to the section(s) of the book with this problem:

https://github.com/rust-lang/book/blob/main/src/ch10-01-syntax.md

Description of the problem:

at the last example in section: In Function Definitions,

last example only suggests the reader to implement PartialOrd to compile the code but didn't show how.
this is the code from book:

fn largest<T>(list: &[T]) -> &T {
    let mut largest = &list[0];

    for item in list {
        if item > largest {
            largest = item;
        }
    }

    largest
}

fn main() {
    let number_list = vec![34, 50, 25, 100, 65];

    let result = largest(&number_list);
    println!("The largest number is {}", result);

    let char_list = vec!['y', 'm', 'a', 'q'];

    let result = largest(&char_list);
    println!("The largest char is {}", result);
}

Suggested fix:

PartialOrd implemented version of the code above should be added to the book where it says implement partialord to make the prior code work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions