diff --git a/README.md b/README.md index f681228..b6a0b17 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -https://tinchicus.com/2022/09/26/rust-listado-del-curso-inicial/ +## https://tinchicus.com/2022/09/26/rust-listado-del-curso-inicial/ - https://tinchicus.com/2022/06/01/rust-usando-a-cargo/ (hola_mundo) - https://tinchicus.com/2022/06/03/rust-strings/ (cadenas) @@ -16,4 +16,5 @@ https://tinchicus.com/2022/09/26/rust-listado-del-curso-inicial/ - https://tinchicus.com/2022/06/21/rust-for/ (bucles) - https://tinchicus.com/2022/06/22/rust-if/ (condicion) - https://tinchicus.com/2022/06/23/rust-match/ (coincidir) -- https://tinchicus.com/2022/06/24/rust-funciones-y-metodos/ (ejemplo01) \ No newline at end of file +- https://tinchicus.com/2022/06/24/rust-funciones-y-metodos/ (ejemplo01) +- https://tinchicus.com/2022/06/27/rust-closures/ (cierre) \ No newline at end of file diff --git a/cierre/Cargo.toml b/cierre/Cargo.toml new file mode 100644 index 0000000..7caad4f --- /dev/null +++ b/cierre/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "cierre" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/cierre/src/main.rs b/cierre/src/main.rs new file mode 100644 index 0000000..19a93cb --- /dev/null +++ b/cierre/src/main.rs @@ -0,0 +1,39 @@ +use std::thread; +use std::time::Duration; + +fn rutina_ejercicio(i: u32, a: u32) { + let cierre = |num| { + println!("Recalculando..."); + thread::sleep(Duration::from_secs(2)); + num + }; + if i < 25 { + println!("Hoy haz {} sentadillas", cierre(i)); + println!("Despues haz {} sentadillas", cierre(i)); + } else { + if a == 3 { + println!("Descansa un poco y recuerda hidratarte"); + } else { + println!("Hoy corre por {} minutos", cierre(i)); + } + } +} + +fn main() { + let valor_especificado = 27; + let numero_al_azar = 5; + + rutina_ejercicio(valor_especificado, numero_al_azar); + + // ejemplo creado por mi + + let imprime_algo = |texto| { + println!("WTF!!!!!"); + texto + }; + + println!( + "Vamos a imprimir el texto....{}", + imprime_algo("Mis cojones mangas 3") + ) +} diff --git a/ejemplo01/src/main.rs b/ejemplo01/src/main.rs index f582d64..401e79d 100644 --- a/ejemplo01/src/main.rs +++ b/ejemplo01/src/main.rs @@ -10,5 +10,5 @@ impl Perro { fn main() { let perro = Perro::nuevo(98, 87); - println!("{} {}", perro.edad, perro.peso) + println!("{} {}", perro.edad, perro.peso); }