Skip to content

Do not mix type parameters and impl Trait #2

@dtolnay

Description

@dtolnay

ndarray-csv/src/lib.rs

Lines 79 to 83 in a69bdf9

/// Read CSV data into a new ndarray with the given shape
pub fn read<A>(shape: (usize, usize), reader: &mut Reader<impl Read>) -> Result<Array2<A>, Error>
where
A: Copy,
for<'de> A: serde::Deserialize<'de>,


Mixing type parameters and impl Trait in the same signature makes it impossible to use with turbofish. Turbofish is commonly needed for signatures where some type parameter appears only in the return type.

use std::io::{Cursor, Read};

fn read<A>(_reader: impl Read) -> A {
    unimplemented!()
}

fn main() {
    let reader = Cursor::new(Vec::new());
    let _: u8 = read(reader); // okay

    let _ = read::<u8>(reader); // not supported
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions