Skip to content

Missing TryInto from usize to float #67182

@jacksun007

Description

@jacksun007

Currently there is no trait bound that will satisfy this very simple algorithm:

fn average<T>(list: &Vec<T>) -> T 
    where T: Div<Output=T> + Add<Output=T> + Default + TryFrom<usize>
{
    let mut total = Default::default();
    if list.len() == 0 {
        total
    }
    else {
        for val in list.iter() {
            total = total + *val;
        }
        total / TryFrom::try_from(list.len()).unwrap()
    }
} 

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions