From 5969526dd1d967b6d6dfe7dd0186c08b20224b53 Mon Sep 17 00:00:00 2001 From: clonbg Date: Mon, 29 May 2023 09:15:22 +0200 Subject: [PATCH] vectores --- README.md | 3 ++- vectores/Cargo.toml | 8 ++++++++ vectores/src/main.rs | 16 ++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 vectores/Cargo.toml create mode 100644 vectores/src/main.rs diff --git a/README.md b/README.md index 5112ab9..282c081 100644 --- a/README.md +++ b/README.md @@ -3,4 +3,5 @@ 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) - https://tinchicus.com/2022/06/06/rust-arrays/ (arreglos) -- https://tinchicus.com/2022/06/07/rust-vector/ (vectores) \ No newline at end of file +- https://tinchicus.com/2022/06/07/rust-vector/ (vectores) +- https://tinchicus.com/2022/06/08/rust-tuple/ (tupla) \ No newline at end of file diff --git a/vectores/Cargo.toml b/vectores/Cargo.toml new file mode 100644 index 0000000..5460520 --- /dev/null +++ b/vectores/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "vectores" +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/vectores/src/main.rs b/vectores/src/main.rs new file mode 100644 index 0000000..5802560 --- /dev/null +++ b/vectores/src/main.rs @@ -0,0 +1,16 @@ +// se diferencia de los arrays en que se puede modificar el tamaño +fn main() { + // definición más explícita + let mut _mi_vector: Vec=Vec::new(); + // otra forma expecificando el tipo + let mut _mi_vector2=vec![4i32,2,4,8,16]; + // otra forma + let mut _mi_vector3=[2,4,8,16]; + // solo definimos el tamaño + let mut _mi_vector4: Vec=Vec::with_capacity(30); + // con un iterador + let _mi_vector5: Vec = (0..10).collect(); + + println!("{}",_mi_vector5[7]) + +}