diff --git a/README.md b/README.md index b6a0b17..9f1d9c0 100644 --- a/README.md +++ b/README.md @@ -17,4 +17,6 @@ - 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) -- https://tinchicus.com/2022/06/27/rust-closures/ (cierre) \ No newline at end of file +- https://tinchicus.com/2022/06/27/rust-closures/ (cierre) +- https://tinchicus.com/2022/06/28/rust-iteradores/ (iter) +- https://tinchicus.com/2022/06/29/rust-el-parametro-_/ (bucles2) \ No newline at end of file diff --git a/bucles2/Cargo.toml b/bucles2/Cargo.toml new file mode 100644 index 0000000..80520c3 --- /dev/null +++ b/bucles2/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "bucles2" +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/bucles2/src/main.rs b/bucles2/src/main.rs new file mode 100644 index 0000000..30dcc01 --- /dev/null +++ b/bucles2/src/main.rs @@ -0,0 +1,8 @@ +fn main() { + let mi_arreglo = ["Lovecraft", "Poe", "Barker", "King"]; + + // Evita avisos en el compilador y sirve para almacenar datos que no son necesarios + for (_, apellido) in mi_arreglo.iter().enumerate() { + println!("{}", apellido); + } +} diff --git a/iter/Cargo.toml b/iter/Cargo.toml new file mode 100644 index 0000000..4ba8732 --- /dev/null +++ b/iter/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "iter" +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/iter/src/main.rs b/iter/src/main.rs new file mode 100644 index 0000000..261d6f1 --- /dev/null +++ b/iter/src/main.rs @@ -0,0 +1,17 @@ +fn main() { + let v1 = vec![1, 2, 3]; + let v1_iter = v1.iter(); + + for val in v1_iter { + println!("{}", val); + } + + let v2 = vec![50, 100, 200]; + let v2_iter = v2.iter(); + + v2_iter.for_each(|e| print!("{}, ", e)); + + let mut v3 = vec![50, 100, 200]; + v3.iter_mut().for_each(|e| *e += 23); + println!("{:?}", v3) +}