Skip to content

partialOrd #81010

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tariqjamil-bwp opened this issue Jan 14, 2021 · 2 comments
Closed

partialOrd #81010

tariqjamil-bwp opened this issue Jan 14, 2021 · 2 comments

Comments

@tariqjamil-bwp
Copy link

//use std::cmp::PartialOrd;
fn largest<T :std::cmp::PartialOrd>(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);
}

(Playground)

Output:

The largest number is 100
The largest char is y

Errors:

   Compiling playground v0.0.1 (/playground)
    Finished dev [unoptimized + debuginfo] target(s) in 1.19s
     Running `target/debug/playground`

@rylev
Copy link
Member

rylev commented Jan 14, 2021

@tj-yazman Can you please describe the error you're seeing in more detail. This code looks correct to me.

@nagisa
Copy link
Member

nagisa commented Jan 14, 2021

Code seems to be broadly copied from https://doc.rust-lang.org/book/ch10-02-traits.html#fixing-the-largest-function-with-trait-bounds and there are various signals indicating this might be a spam, similar to #80773. Closing for now, but if the author does provide more explanation, we can reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants