iteradores y _
This commit is contained in:
@@ -17,4 +17,6 @@
|
|||||||
- https://tinchicus.com/2022/06/22/rust-if/ (condicion)
|
- https://tinchicus.com/2022/06/22/rust-if/ (condicion)
|
||||||
- https://tinchicus.com/2022/06/23/rust-match/ (coincidir)
|
- 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/24/rust-funciones-y-metodos/ (ejemplo01)
|
||||||
- https://tinchicus.com/2022/06/27/rust-closures/ (cierre)
|
- 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)
|
||||||
8
bucles2/Cargo.toml
Normal file
8
bucles2/Cargo.toml
Normal file
@@ -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]
|
||||||
8
bucles2/src/main.rs
Normal file
8
bucles2/src/main.rs
Normal file
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
8
iter/Cargo.toml
Normal file
8
iter/Cargo.toml
Normal file
@@ -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]
|
||||||
17
iter/src/main.rs
Normal file
17
iter/src/main.rs
Normal file
@@ -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)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user