Skip to content

generics1: does not require use of explicit generics #1448

Closed
@benjaminbauer

Description

@benjaminbauer

The idiomatic solution for generics1 is to simply remove the explicit type from the variable binding since it can be inferred:

fn main() {
    let mut shopping_list = Vec::new();
    shopping_list.push("milk");
}

The hint says:

Vectors in Rust make use of generics to create dynamically sized arrays of any type.
You need to tell the compiler what type we are pushing onto this vector.

Two problems with this:

  1. The solution is better without specifying a type and thus is not teaching/requiring the explicit use of generics
  2. The hint is wrong, because there is not need to tell the compiler the type

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions