This commit is contained in:
2023-06-23 17:00:46 +02:00
parent e5271ed247
commit 643fda700c
3 changed files with 41 additions and 0 deletions

8
enums/Cargo.toml Normal file
View File

@@ -0,0 +1,8 @@
[package]
name = "enums"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

32
enums/src/main.rs Normal file
View File

@@ -0,0 +1,32 @@
enum Numerado1 {
TipoTuple(f32, i32, String),
TipoStruct { var1: i32, var2: f32 },
StructTuple(i32),
Variable,
}
enum Numerado2 {
TipoTuple(f32, i32, String),
TipoStruct { var1: i32, var2: f32 },
StructTuple(i32),
}
fn main() {
let mut texto1 = "".to_owned();
let mut texto2 = "".to_owned();
let mut num1 = 0f32;
let valor = Numerado1::TipoTuple(3.14, 1, "Hola".to_owned());
let valor2 = Numerado2::TipoTuple(3.14, 0, "Mundo".to_owned());
if let Numerado1::TipoTuple(f, i, s) = valor {
texto1 = s;
num1 = f;
}
if let Numerado2::TipoTuple(f, i, s) = valor2 {
texto2 = s;
}
println!("{}, {}! del hombre {}", texto1, texto2, num1)
}