Skip to content

implement: src/generics -- generic roster queries, bounded type params #8

@BryanChasko

Description

@BryanChasko

topic: generics

generics let functions and structs work over multiple types while staying type-safe.

concepts to demonstrate

  • generic function syntax fn top_n<T: Ord>(items: &[T], n: usize) -> Vec<&T>
  • generic structs: StatLeader<T>
  • trait bounds: where T: Display + PartialOrd
  • monomorphization (rust compiles one version per concrete type used)

patriots theme

generic top_n that works on rushing yards, receiving yards, or passing rating.
StatLeader<Player> struct holding a typed winner and their value.

file

src/generics/roster_query.rs

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