Tipos de Datos Genéricos

Puedes usar genéricos para abstraer el tipo de campo concreto:

#[derive(Debug)]
struct Point<T> {
    x: T,
    y: T,
}

fn main() {
    let integer = Point { x: 5, y: 10 };
    let float = Point { x: 1.0, y: 4.0 };
    println!("{integer:?} and {float:?}");
}
  • Prueba a declarar una nueva variable let p = Point { x: 5, y: 10.0 };.

  • Corrige el código para permitir puntos que tengan elementos de distintos tipos.