DEV Community

Héctor David Leiva Gamboa
Héctor David Leiva Gamboa

Posted on

Día 4/365. Tipos de datos en Rust: Escalares y compuestos.

Rust organiza los tipos de datos en dos categorías principales: Escalares y Compuestos. Este diseño busca maximizar la seguridad y eficiencia en el manejo de datos. Aquí te explico brevemente cada categoría y algunas funcionalidades clave.

Tipos escalares

Los tipos escalares representan un solo valor. Rust incluye cuatro tipos principales:
Enteros (i8, u8, i32, etc.): Valores positivos o negativos con tamaños específicos.
Punto flotante (f32, f64): Para números decimales.
Booleanos (bool): Representan true o false.
Caracteres (char): Representan un carácter Unicode, como 'a' o '😊'.

Son ideales para cálculos simples o datos básicos.

Tipos compuestos

Los tipos compuestos agrupan múltiples valores:

Tuplas: Colecciones de valores heterogéneos, útiles para agrupar datos relacionados.

let persona: (&str, i32) = ("Juan", 30);
println!("Nombre: {}, Edad: {}", persona.0, persona.1);
Enter fullscreen mode Exit fullscreen mode

Arreglos ([T; N]): Almacenan valores homogéneos con tamaño fijo.

let numeros = [1, 2, 3];
println!("Primer número: {}", numeros[0]);
Enter fullscreen mode Exit fullscreen mode

Vectores (Vec): Una colección dinámica para valores del mismo tipo. Perfectos cuando el tamaño de los datos es variable.

let mut vec = Vec::new();
vec.push(10);
vec.push(20);
println!("{:?}", vec);
Enter fullscreen mode Exit fullscreen mode

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay