organizado en carpetas
This commit is contained in:
35
curso_tinchicusls/README.md
Normal file
35
curso_tinchicusls/README.md
Normal file
@@ -0,0 +1,35 @@
|
||||
## 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)
|
||||
- https://tinchicus.com/2022/06/08/rust-tuple/ (tupla)
|
||||
- https://tinchicus.com/2022/06/09/rust-hash-map/ (mapeo)
|
||||
- https://tinchicus.com/2022/06/10/rust-slice/ (slices)
|
||||
- https://tinchicus.com/2022/06/13/rust-pasando-valores/ (porvalor y porreferencia)
|
||||
- https://tinchicus.com/2022/06/14/rust-la-libreria-std/
|
||||
- https://tinchicus.com/2022/06/15/rust-println/ (println)
|
||||
- https://tinchicus.com/2022/06/16/rust-format/ (format)
|
||||
- https://tinchicus.com/2022/06/17/rust-read_line/ (entrada)
|
||||
- https://tinchicus.com/2022/06/20/rust-argumentos/ (argumento)
|
||||
- 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)
|
||||
- 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)
|
||||
- https://tinchicus.com/2022/06/30/rust-loop-27/ (arreglos2)
|
||||
- https://tinchicus.com/2022/07/01/rust-loop-labels/ (nombre)
|
||||
- https://tinchicus.com/2022/07/04/rust-while/ (while)
|
||||
- https://tinchicus.com/2022/07/05/rust-funciones-recursivas/ (recursiva)
|
||||
- https://tinchicus.com/2022/07/06/rust-punto-y-coma/ (ejemplo02)
|
||||
- https://tinchicus.com/2022/07/12/rust-memoria-estatica/ (ejemplo03)
|
||||
- https://tinchicus.com/2022/07/13/rust-struct/ (estructura)
|
||||
- https://tinchicus.com/2022/07/14/rust-struct-en-multiples-archivos/ (estructura2)
|
||||
- https://tinchicus.com/2022/07/15/rust-tuple-struct/ (nuevotipo)
|
||||
- https://tinchicus.com/2022/07/18/rust-enum/ (enums)
|
||||
- https://tinchicus.com/2022/07/19/rust-patrones-y-coincidencias/ (iflet)
|
||||
- https://tinchicus.com/2022/07/20/rust-ownership/ (prop)
|
||||
- https://tinchicus.com/2022/07/21/rust-copy-trait/ (copiari32, copiar)
|
||||
8
curso_tinchicusls/argumento/Cargo.toml
Normal file
8
curso_tinchicusls/argumento/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "argumento"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
12
curso_tinchicusls/argumento/src/main.rs
Normal file
12
curso_tinchicusls/argumento/src/main.rs
Normal file
@@ -0,0 +1,12 @@
|
||||
use std::env;
|
||||
|
||||
// cargo run Huevos Pelotas Narices
|
||||
fn main() {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
|
||||
println!(
|
||||
"Pasaste {:?} argumentos, ellos fueron {:?}",
|
||||
args.len() - 1,
|
||||
&args[1..]
|
||||
);
|
||||
}
|
||||
8
curso_tinchicusls/arreglos/Cargo.toml
Normal file
8
curso_tinchicusls/arreglos/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "arreglos"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
21
curso_tinchicusls/arreglos/src/main.rs
Normal file
21
curso_tinchicusls/arreglos/src/main.rs
Normal file
@@ -0,0 +1,21 @@
|
||||
fn main() {
|
||||
// definimos un array
|
||||
let mi_arreglo_3 = ["Lovecraft", "Poe", "Barker", "King"];
|
||||
// array mutable con 4 enteros
|
||||
let mut _mi_arreglo_2: [i32; 4] = [2, 4, 8, 16];
|
||||
// arreglo vacío tipo string
|
||||
let mut _arreglo_vacio: [&str; 0] = [];
|
||||
// crea el array con cuatro veces el 123
|
||||
let arreglo = [123; 4];
|
||||
// imprimimos para que no den error
|
||||
println!("{} {} {} ", mi_arreglo_3[1], _mi_arreglo_2[2], arreglo[3]);
|
||||
|
||||
let mut mi_arreglo: [&str; 4] = ["", "", "", ""];
|
||||
|
||||
mi_arreglo[0] = "Lovecraft";
|
||||
mi_arreglo[1] = "Poe";
|
||||
mi_arreglo[2] = "Barker";
|
||||
mi_arreglo[3] = "King";
|
||||
|
||||
println!("{}, {}, {}, {}", mi_arreglo[0], mi_arreglo[1], mi_arreglo[2], mi_arreglo[3]);
|
||||
}
|
||||
8
curso_tinchicusls/arreglos2/Cargo.toml
Normal file
8
curso_tinchicusls/arreglos2/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "arreglos2"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
12
curso_tinchicusls/arreglos2/src/main.rs
Normal file
12
curso_tinchicusls/arreglos2/src/main.rs
Normal file
@@ -0,0 +1,12 @@
|
||||
fn main() {
|
||||
let mi_arreglo = ["Lovecraft", "Poe", "Barker", "King"];
|
||||
let mut i = 0;
|
||||
|
||||
loop {
|
||||
if i >= mi_arreglo.len() {
|
||||
break;
|
||||
}
|
||||
println!("{}", mi_arreglo[i]);
|
||||
i = i + 1;
|
||||
}
|
||||
}
|
||||
8
curso_tinchicusls/bucles/Cargo.toml
Normal file
8
curso_tinchicusls/bucles/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "bucles"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
7
curso_tinchicusls/bucles/src/main.rs
Normal file
7
curso_tinchicusls/bucles/src/main.rs
Normal file
@@ -0,0 +1,7 @@
|
||||
fn main() {
|
||||
let mi_arreglo = ["Lovecraft", "Poe", "Barker", "King"];
|
||||
|
||||
for (pos, apellido) in mi_arreglo.iter().enumerate() {
|
||||
println!("{} esta en la posicion {}", apellido, pos);
|
||||
}
|
||||
}
|
||||
8
curso_tinchicusls/bucles2/Cargo.toml
Normal file
8
curso_tinchicusls/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
curso_tinchicusls/bucles2/src/main.rs
Normal file
8
curso_tinchicusls/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
curso_tinchicusls/cadenas/Cargo.toml
Normal file
8
curso_tinchicusls/cadenas/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "cadenas"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
25
curso_tinchicusls/cadenas/src/main.rs
Normal file
25
curso_tinchicusls/cadenas/src/main.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
fn main() {
|
||||
string1();
|
||||
string2();
|
||||
}
|
||||
fn string1() {
|
||||
let cadena1 = "Tinchicus.com";
|
||||
let cadena2 = " es el ";
|
||||
let cadena3 = "mejor lugar para aprender";
|
||||
// utilizamos a to_owned para convertir este segmento en una string y podamos concatenar los otros segmentos a este
|
||||
let _renglon = cadena1.to_owned() + cadena2 + cadena3;
|
||||
|
||||
println!("{} {}", _renglon, cadena3)
|
||||
}
|
||||
|
||||
fn string2() {
|
||||
let mut _renglon_final = String::new();
|
||||
|
||||
let cadena1 = "Tinchicus.com";
|
||||
let cadena2 = " es el ";
|
||||
let cadena3 = "mejor lugar para aprender";
|
||||
|
||||
_renglon_final = format!("{}{}{}", cadena1, cadena2, cadena3);
|
||||
|
||||
println!("{}", _renglon_final);
|
||||
}
|
||||
8
curso_tinchicusls/cierre/Cargo.toml
Normal file
8
curso_tinchicusls/cierre/Cargo.toml
Normal file
@@ -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]
|
||||
39
curso_tinchicusls/cierre/src/main.rs
Normal file
39
curso_tinchicusls/cierre/src/main.rs
Normal file
@@ -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")
|
||||
)
|
||||
}
|
||||
8
curso_tinchicusls/coincidir/Cargo.toml
Normal file
8
curso_tinchicusls/coincidir/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "coincidir"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
46
curso_tinchicusls/coincidir/src/main.rs
Normal file
46
curso_tinchicusls/coincidir/src/main.rs
Normal file
@@ -0,0 +1,46 @@
|
||||
fn main() {
|
||||
let booleano = false;
|
||||
|
||||
let binario;
|
||||
match booleano {
|
||||
false => binario = 0,
|
||||
true => binario = 1,
|
||||
}
|
||||
println!("{} -> {}", booleano, binario);
|
||||
|
||||
let booleano = !booleano;
|
||||
let binario = match booleano {
|
||||
false => 0,
|
||||
true => 1,
|
||||
};
|
||||
println!("{} -> {}", booleano, binario);
|
||||
|
||||
let x = 1;
|
||||
|
||||
match x {
|
||||
1 | 2 | 3 => println!("Works"),
|
||||
_ => println!("Noooo"),
|
||||
}
|
||||
|
||||
match x {
|
||||
1..=10 => println!("Works to"),
|
||||
_ => println!("Noooo"),
|
||||
}
|
||||
|
||||
let y = 'G';
|
||||
|
||||
match y {
|
||||
'A'..='Z' => println!("Works to"),
|
||||
_ => println!("Noooo"),
|
||||
}
|
||||
|
||||
match y {
|
||||
p @ 'A'..='Z' => println!("{}", p),
|
||||
_ => println!("Noo"),
|
||||
}
|
||||
|
||||
match y {
|
||||
p @ 'A'..='F' | p @ 'G'..='Z' => println!("{}", p),
|
||||
_ => println!("Noo"),
|
||||
}
|
||||
}
|
||||
8
curso_tinchicusls/condicion/Cargo.toml
Normal file
8
curso_tinchicusls/condicion/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "condicion"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
19
curso_tinchicusls/condicion/src/main.rs
Normal file
19
curso_tinchicusls/condicion/src/main.rs
Normal file
@@ -0,0 +1,19 @@
|
||||
use std::io;
|
||||
|
||||
fn main() {
|
||||
let mut entrada: String = String::new();
|
||||
|
||||
for _ in 0..3 {
|
||||
io::stdin().read_line(&mut entrada).unwrap();
|
||||
let n: i32 = entrada.trim().parse().unwrap();
|
||||
|
||||
if n < 0 {
|
||||
println!("{} es negativo", n);
|
||||
} else if n > 0 {
|
||||
println!("{} es positivo", n);
|
||||
} else {
|
||||
println!("Es cero");
|
||||
}
|
||||
entrada.clear();
|
||||
}
|
||||
}
|
||||
8
curso_tinchicusls/copiar/Cargo.toml
Normal file
8
curso_tinchicusls/copiar/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "copiar"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
12
curso_tinchicusls/copiar/src/main.rs
Normal file
12
curso_tinchicusls/copiar/src/main.rs
Normal file
@@ -0,0 +1,12 @@
|
||||
fn sumar(v1: Vec<i32>, v2: Vec<i32>) -> (Vec<i32>, Vec<i32>, i32) {
|
||||
let sum = v1.iter().fold(0i32, |a, &b| a + b);
|
||||
let prod = v2.iter().fold(1i32, |a, &b| a * b);
|
||||
return (v1, v2, sum + prod);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let vecuno = vec![2, 3, 5];
|
||||
let vecdos = vec![3, 5];
|
||||
let (vecuno, vecdos, rta) = sumar(vecuno, vecdos);
|
||||
println!("{} + {} = {}", vecuno[0], vecdos[0], rta);
|
||||
}
|
||||
8
curso_tinchicusls/copiari32/Cargo.toml
Normal file
8
curso_tinchicusls/copiari32/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "copiari32"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
9
curso_tinchicusls/copiari32/src/main.rs
Normal file
9
curso_tinchicusls/copiari32/src/main.rs
Normal file
@@ -0,0 +1,9 @@
|
||||
fn incrementar(n: i32) -> i32 {
|
||||
n + 32
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let num = 10i32;
|
||||
let num2 = incrementar(num);
|
||||
println!("num: {}, num2: {}", num, num2);
|
||||
}
|
||||
8
curso_tinchicusls/ejemplo01/Cargo.toml
Normal file
8
curso_tinchicusls/ejemplo01/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "ejemplo01"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
14
curso_tinchicusls/ejemplo01/src/main.rs
Normal file
14
curso_tinchicusls/ejemplo01/src/main.rs
Normal file
@@ -0,0 +1,14 @@
|
||||
struct Perro {
|
||||
peso: i32,
|
||||
edad: i32,
|
||||
}
|
||||
impl Perro {
|
||||
fn nuevo(a: i32, b: i32) -> Perro {
|
||||
Perro { peso: a, edad: b }
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let perro = Perro::nuevo(98, 87);
|
||||
println!("{} {}", perro.edad, perro.peso);
|
||||
}
|
||||
8
curso_tinchicusls/ejemplo02/Cargo.toml
Normal file
8
curso_tinchicusls/ejemplo02/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "ejemplo02"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
22
curso_tinchicusls/ejemplo02/src/main.rs
Normal file
22
curso_tinchicusls/ejemplo02/src/main.rs
Normal file
@@ -0,0 +1,22 @@
|
||||
fn main() {
|
||||
let x = 5u32;
|
||||
|
||||
let y = {
|
||||
let x_cuadrado = x * x;
|
||||
let x_cubo = x_cuadrado * x;
|
||||
x_cubo + x_cuadrado + x
|
||||
};
|
||||
|
||||
// La variable z no tiene ningún valor, no es devuelto por el punto y coma
|
||||
let z = {
|
||||
2 * x;
|
||||
};
|
||||
|
||||
// la variable h tiene el valor de 2*x por que es devuelta al no tener punto y coma.
|
||||
let h = { 2 * x };
|
||||
|
||||
println!("x es {:?}", x);
|
||||
println!("y es {:?}", y);
|
||||
println!("z es {:?}", z);
|
||||
println!("h es {:?}", h);
|
||||
}
|
||||
8
curso_tinchicusls/ejemplo03/Cargo.toml
Normal file
8
curso_tinchicusls/ejemplo03/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "ejemplo03"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
16
curso_tinchicusls/ejemplo03/src/main.rs
Normal file
16
curso_tinchicusls/ejemplo03/src/main.rs
Normal file
@@ -0,0 +1,16 @@
|
||||
fn main() {
|
||||
let x = 5u32;
|
||||
|
||||
let y: &u32;
|
||||
{
|
||||
let x_cuadrado = x * x;
|
||||
let x_cubo = x_cuadrado * x;
|
||||
// da un error por que la memoria es eliminada
|
||||
// cuando es eliminado el scope
|
||||
y = &(x_cubo + x_cuadrado + x);
|
||||
};
|
||||
|
||||
let z = { 2 * x };
|
||||
|
||||
println!("x={}, y={}, z={}", z, y, z)
|
||||
}
|
||||
8
curso_tinchicusls/entrada/Cargo.toml
Normal file
8
curso_tinchicusls/entrada/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "entrada"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
30
curso_tinchicusls/entrada/src/main.rs
Normal file
30
curso_tinchicusls/entrada/src/main.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
use std::io;
|
||||
|
||||
fn main() {
|
||||
let lector: io::Stdin = io::stdin();
|
||||
let mut entrada: String = String::new();
|
||||
|
||||
// metodo 1 de manejar los errores
|
||||
lector.read_line(&mut entrada).expect("Fallo lectura");
|
||||
println!("Leido {}", entrada);
|
||||
|
||||
// metodo 2 de manejar los errores
|
||||
let resultado: Result<usize, io::Error> = lector.read_line(&mut entrada);
|
||||
|
||||
if resultado.is_err() {
|
||||
println!("Fallo el ingreso de datos");
|
||||
return;
|
||||
}
|
||||
|
||||
println!("Leido {}", entrada);
|
||||
|
||||
// metodo 3 de manejar los errores
|
||||
let trimmed = entrada.trim();
|
||||
let opcion: Option<i32> = trimmed.parse().ok();
|
||||
|
||||
match opcion {
|
||||
// match equivale a switch de otros lenguajes
|
||||
Some(i) => println!("Tu entero de la entrada: {}", i),
|
||||
None => println!("Este no es un entero: {}", trimmed),
|
||||
};
|
||||
}
|
||||
8
curso_tinchicusls/enums/Cargo.toml
Normal file
8
curso_tinchicusls/enums/Cargo.toml
Normal 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
curso_tinchicusls/enums/src/main.rs
Normal file
32
curso_tinchicusls/enums/src/main.rs
Normal 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)
|
||||
}
|
||||
8
curso_tinchicusls/estructura/Cargo.toml
Normal file
8
curso_tinchicusls/estructura/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "estructura"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
65
curso_tinchicusls/estructura/src/main.rs
Normal file
65
curso_tinchicusls/estructura/src/main.rs
Normal file
@@ -0,0 +1,65 @@
|
||||
struct Persona {
|
||||
nombre: String,
|
||||
edad: i32,
|
||||
apellido: String,
|
||||
}
|
||||
|
||||
struct Area {
|
||||
oficina: String,
|
||||
puesto: String,
|
||||
}
|
||||
|
||||
struct Persona2 {
|
||||
nombre: String,
|
||||
edad: i32,
|
||||
apellido: String,
|
||||
area: Area,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// usuario1
|
||||
let usuario = Persona {
|
||||
nombre: String::from("Martín"),
|
||||
apellido: String::from("Miranda"),
|
||||
edad: 33,
|
||||
};
|
||||
|
||||
println!(
|
||||
"{} {}, {} años",
|
||||
usuario.nombre, usuario.apellido, usuario.edad
|
||||
);
|
||||
|
||||
// usuario2
|
||||
let mut usuario2 = Persona {
|
||||
nombre: String::from("Federico"),
|
||||
apellido: String::from("Caco"),
|
||||
edad: 12,
|
||||
};
|
||||
|
||||
// se puede cambiar por que usuario2 es mutable
|
||||
usuario2.edad = 22;
|
||||
|
||||
println!(
|
||||
"{} {}, {} años",
|
||||
usuario2.nombre, usuario2.apellido, usuario2.edad
|
||||
);
|
||||
|
||||
// struct dentro de un struct
|
||||
// usuario3
|
||||
let mut usuario3 = Persona2 {
|
||||
nombre: String::from("Lucas"),
|
||||
apellido: String::from("Pelotas"),
|
||||
edad: 76,
|
||||
area: Area {
|
||||
oficina: String::from("IT"),
|
||||
puesto: String::from("Tecnico"),
|
||||
},
|
||||
};
|
||||
usuario3.edad = 45;
|
||||
|
||||
println!("Nombre: {}", usuario3.nombre);
|
||||
println!("Apellido: {}", usuario3.apellido);
|
||||
println!("Edad: {}", usuario3.edad);
|
||||
println!("Oficina: {}", usuario3.area.oficina);
|
||||
println!("Puesto: {}", usuario3.area.puesto);
|
||||
}
|
||||
8
curso_tinchicusls/estructura2/Cargo.toml
Normal file
8
curso_tinchicusls/estructura2/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "estructura2"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
47
curso_tinchicusls/estructura2/src/main.rs
Normal file
47
curso_tinchicusls/estructura2/src/main.rs
Normal file
@@ -0,0 +1,47 @@
|
||||
mod persona;
|
||||
use persona::*;
|
||||
fn main() {
|
||||
let usuario = Persona {
|
||||
nombre: String::from("Martin"),
|
||||
apellido: String::from("Miranda"),
|
||||
edad: 45,
|
||||
area: Area {
|
||||
oficina: String::from("IT"),
|
||||
puesto: String::from("Desarrollador"),
|
||||
},
|
||||
nomina: Nomina {
|
||||
bruto: 100000,
|
||||
neto: 50000,
|
||||
},
|
||||
};
|
||||
|
||||
println!("Nombre: {}", usuario.nombre);
|
||||
println!("Apellido: {}", usuario.apellido);
|
||||
println!("Edad: {}", usuario.edad);
|
||||
println!("Oficina: {}", usuario.area.oficina);
|
||||
println!("Puesto: {}", usuario.area.puesto);
|
||||
println!("Bruto: {}", usuario.nomina.bruto);
|
||||
println!("Neto: {}", usuario.nomina.neto);
|
||||
|
||||
let usuario2 = Persona {
|
||||
nombre: String::from("Enzo"),
|
||||
apellido: String::from("Tortore"),
|
||||
edad: 33,
|
||||
area: Area {
|
||||
oficina: String::from("DB"),
|
||||
puesto: String::from("Administrador"),
|
||||
},
|
||||
nomina: Nomina {
|
||||
bruto: usuario.nomina.bruto,
|
||||
neto: usuario.nomina.neto,
|
||||
},
|
||||
};
|
||||
|
||||
println!("Nombre: {}", usuario2.nombre);
|
||||
println!("Apellido: {}", usuario2.apellido);
|
||||
println!("Edad: {}", usuario2.edad);
|
||||
println!("Oficina: {}", usuario2.area.oficina);
|
||||
println!("Puesto: {}", usuario2.area.puesto);
|
||||
println!("Bruto: {}", usuario2.nomina.bruto);
|
||||
println!("Neto: {}", usuario2.nomina.neto);
|
||||
}
|
||||
4
curso_tinchicusls/estructura2/src/persona/area.rs
Normal file
4
curso_tinchicusls/estructura2/src/persona/area.rs
Normal file
@@ -0,0 +1,4 @@
|
||||
pub struct Area {
|
||||
pub oficina: String,
|
||||
pub puesto: String,
|
||||
}
|
||||
12
curso_tinchicusls/estructura2/src/persona/mod.rs
Normal file
12
curso_tinchicusls/estructura2/src/persona/mod.rs
Normal file
@@ -0,0 +1,12 @@
|
||||
pub mod area;
|
||||
pub use area::*;
|
||||
pub mod nomina;
|
||||
pub use nomina::*;
|
||||
|
||||
pub struct Persona {
|
||||
pub nombre: String,
|
||||
pub edad: i32,
|
||||
pub apellido: String,
|
||||
pub area: Area,
|
||||
pub nomina: Nomina,
|
||||
}
|
||||
4
curso_tinchicusls/estructura2/src/persona/nomina.rs
Normal file
4
curso_tinchicusls/estructura2/src/persona/nomina.rs
Normal file
@@ -0,0 +1,4 @@
|
||||
pub struct Nomina {
|
||||
pub bruto: i32,
|
||||
pub neto: i32,
|
||||
}
|
||||
8
curso_tinchicusls/format/Cargo.toml
Normal file
8
curso_tinchicusls/format/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "format"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
23
curso_tinchicusls/format/src/main.rs
Normal file
23
curso_tinchicusls/format/src/main.rs
Normal file
@@ -0,0 +1,23 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
let mut visual = format!("{} {}", 23, 89);
|
||||
println!("{}", visual);
|
||||
visual = format!("{} {1} {} {0}", "Hola", "Mundo");
|
||||
println!("{}", visual);
|
||||
visual = format!("{t} {a} {b} {a}", a = "Hola", b = "Mundo", t = 23);
|
||||
println!("{}", visual);
|
||||
visual = format!("{:.4}", 3.1415927);
|
||||
println!("{}", visual);
|
||||
|
||||
let v1 = format!("{:.3}", 3.1415927);
|
||||
let v2 = format!("{:b}", 55);
|
||||
let v3 = format!("{:+}!", 5);
|
||||
let v4 = format!("{:x}", 95);
|
||||
let v5 = format!("{:#x}", 95);
|
||||
|
||||
println!("{}", v1);
|
||||
println!("{}", v2);
|
||||
println!("{}", v3);
|
||||
println!("{}", v4);
|
||||
println!("{}", v5);
|
||||
}
|
||||
1
curso_tinchicusls/hola_mundo/.gitignore
vendored
Normal file
1
curso_tinchicusls/hola_mundo/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/target
|
||||
8
curso_tinchicusls/hola_mundo/Cargo.toml
Normal file
8
curso_tinchicusls/hola_mundo/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "hola_mundo"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
50
curso_tinchicusls/hola_mundo/src/main.rs
Normal file
50
curso_tinchicusls/hola_mundo/src/main.rs
Normal file
@@ -0,0 +1,50 @@
|
||||
/// Statics, son como constantes globales
|
||||
static H: i32 = 21;
|
||||
|
||||
/// Main
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
// si no se especifica es inmutable
|
||||
entero();
|
||||
enteromutable();
|
||||
// unsignet ocupa menos espacio en memoria
|
||||
signet();
|
||||
unsignet();
|
||||
// const no se pueden modificar
|
||||
constante();
|
||||
//static declarada fuera
|
||||
println!("{H}");
|
||||
// castear (parsear)
|
||||
castear(8);
|
||||
}
|
||||
|
||||
fn entero() {
|
||||
let x = 1;
|
||||
println!("{x}");
|
||||
}
|
||||
|
||||
fn enteromutable() {
|
||||
let mut x = 1;
|
||||
x = x + 3;
|
||||
println!("{x}");
|
||||
}
|
||||
|
||||
fn signet() {
|
||||
let sig: i32 = 2048;
|
||||
println!("{sig}");
|
||||
}
|
||||
|
||||
fn unsignet() {
|
||||
let unsig: u32 = 2048;
|
||||
println!("{unsig}");
|
||||
}
|
||||
|
||||
fn constante() {
|
||||
const PI: f32 = 3.14159265;
|
||||
println!("{PI}");
|
||||
}
|
||||
|
||||
fn castear(a: i32) {
|
||||
let valor_final = a as u32;
|
||||
println!("{valor_final}");
|
||||
}
|
||||
8
curso_tinchicusls/iflet/Cargo.toml
Normal file
8
curso_tinchicusls/iflet/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "iflet"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
14
curso_tinchicusls/iflet/src/main.rs
Normal file
14
curso_tinchicusls/iflet/src/main.rs
Normal file
@@ -0,0 +1,14 @@
|
||||
fn main() {
|
||||
let x = 1;
|
||||
|
||||
match x {
|
||||
1 => println!("uno"),
|
||||
_ => println!("no encontrado"),
|
||||
}
|
||||
|
||||
if let 1 = x {
|
||||
println!("uno")
|
||||
} else {
|
||||
println!("no encontrado")
|
||||
}
|
||||
}
|
||||
8
curso_tinchicusls/iter/Cargo.toml
Normal file
8
curso_tinchicusls/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
curso_tinchicusls/iter/src/main.rs
Normal file
17
curso_tinchicusls/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)
|
||||
}
|
||||
8
curso_tinchicusls/mapeo/Cargo.toml
Normal file
8
curso_tinchicusls/mapeo/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "mapeo"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
77
curso_tinchicusls/mapeo/src/main.rs
Normal file
77
curso_tinchicusls/mapeo/src/main.rs
Normal file
@@ -0,0 +1,77 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
fn main() {
|
||||
println!("-- Ejercicio 1");
|
||||
let mut mapa = HashMap::new();
|
||||
|
||||
mapa.insert('A', 10);
|
||||
mapa.insert('B', 20);
|
||||
|
||||
let idx = 'A';
|
||||
let mapeo = mapa.get(&idx);
|
||||
println!("{:?}", mapeo);
|
||||
|
||||
println!("-- Ejercicio 2");
|
||||
|
||||
let mut mapa = HashMap::new();
|
||||
|
||||
mapa.insert(String::from("primero"), 10);
|
||||
mapa.insert(String::from("segundo"), 20);
|
||||
|
||||
let idx = String::from("primero");
|
||||
let mapeo = mapa.get(&idx);
|
||||
println!("{:?}", mapeo);
|
||||
|
||||
println!("-- Ejercicio 3");
|
||||
|
||||
let mut mapa = HashMap::new();
|
||||
|
||||
mapa.insert(String::from("primero"), 10);
|
||||
mapa.insert(String::from("segundo"), 20);
|
||||
|
||||
for (clave, valor) in &mapa {
|
||||
println!("{}: {}", clave, valor);
|
||||
}
|
||||
|
||||
println!("-- Ejercicio 4");
|
||||
|
||||
let mut mapa = HashMap::new();
|
||||
|
||||
mapa.insert(String::from("primero"), 10);
|
||||
mapa.insert(String::from("segundo"), 20);
|
||||
|
||||
mapa.insert(String::from("primero"), 30);
|
||||
|
||||
for (clave, valor) in &mapa {
|
||||
println!("{}: {}", clave, valor);
|
||||
}
|
||||
|
||||
println!("-- Ejercicio 5");
|
||||
|
||||
let mut mapa = HashMap::new();
|
||||
|
||||
mapa.insert(String::from("primero"), 10);
|
||||
mapa.insert(String::from("segundo"), 20);
|
||||
|
||||
mapa.entry(String::from("primero")).or_insert(30);
|
||||
mapa.entry(String::from("tercero")).or_insert(40);
|
||||
|
||||
for (clave, valor) in &mapa {
|
||||
println!("{}: {}", clave, valor);
|
||||
}
|
||||
|
||||
println!("-- Ejercicio 6");
|
||||
|
||||
let texto = "hola mundo maravilloso mundo";
|
||||
|
||||
let mut mapa = HashMap::new();
|
||||
|
||||
for palabra in texto.split_whitespace() {
|
||||
let contar = mapa.entry(palabra).or_insert(0);
|
||||
*contar += 1;
|
||||
}
|
||||
|
||||
for (clave, valor) in &mapa {
|
||||
println!("{}: {}", clave, valor);
|
||||
}
|
||||
}
|
||||
8
curso_tinchicusls/nombre/Cargo.toml
Normal file
8
curso_tinchicusls/nombre/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "nombre"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
13
curso_tinchicusls/nombre/src/main.rs
Normal file
13
curso_tinchicusls/nombre/src/main.rs
Normal file
@@ -0,0 +1,13 @@
|
||||
fn main() {
|
||||
'bucle_externo: for x in 0..10 {
|
||||
'bucle_interno: for y in 0..10 {
|
||||
if x % 2 == 0 {
|
||||
continue 'bucle_externo;
|
||||
}
|
||||
if y % 2 != 0 {
|
||||
continue 'bucle_interno;
|
||||
}
|
||||
println!("X: {}, Y: {}", x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
8
curso_tinchicusls/nuevotipo/Cargo.toml
Normal file
8
curso_tinchicusls/nuevotipo/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "nuevotipo"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
11
curso_tinchicusls/nuevotipo/src/main.rs
Normal file
11
curso_tinchicusls/nuevotipo/src/main.rs
Normal file
@@ -0,0 +1,11 @@
|
||||
// tuple-struct;
|
||||
struct MiPi(f32);
|
||||
|
||||
fn main() {
|
||||
// creamos objeto del tipo MiPi
|
||||
let mi_pi = MiPi(22f32 / 7f32);
|
||||
println!("mi_pi = {:?}", mi_pi.0);
|
||||
// asignación de patrón de tipo nuevo
|
||||
let MiPi(pi) = mi_pi;
|
||||
println!("pi = {}", pi);
|
||||
}
|
||||
8
curso_tinchicusls/porreferencia/Cargo.toml
Normal file
8
curso_tinchicusls/porreferencia/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "porreferencia"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
12
curso_tinchicusls/porreferencia/src/main.rs
Normal file
12
curso_tinchicusls/porreferencia/src/main.rs
Normal file
@@ -0,0 +1,12 @@
|
||||
fn agregar(a: &i32, b: &i32) -> i32 {
|
||||
//pide que los datos sean referencias
|
||||
a + b
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let v1 = &3; // & referencia
|
||||
let v2 = *v1; // * desreferencia
|
||||
let valor = agregar(v1, &v2);
|
||||
|
||||
println!("{}", valor);
|
||||
}
|
||||
8
curso_tinchicusls/porvalor/Cargo.toml
Normal file
8
curso_tinchicusls/porvalor/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "porvalor"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
9
curso_tinchicusls/porvalor/src/main.rs
Normal file
9
curso_tinchicusls/porvalor/src/main.rs
Normal file
@@ -0,0 +1,9 @@
|
||||
fn agregar(a: i32, b: i32) -> i32 {
|
||||
// como no tiene punto y coma este dato es retornado
|
||||
a + b
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let valor = agregar(3, 5);
|
||||
println!("{}", valor)
|
||||
}
|
||||
8
curso_tinchicusls/println/Cargo.toml
Normal file
8
curso_tinchicusls/println/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "println"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
10
curso_tinchicusls/println/src/main.rs
Normal file
10
curso_tinchicusls/println/src/main.rs
Normal file
@@ -0,0 +1,10 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
|
||||
let v1 = " es el ";
|
||||
let v2 = "lugar para ";
|
||||
|
||||
println!("tinchicus.com{}{}aprender", v1, v2);
|
||||
|
||||
println!("tinchicus.com{1}{0}aprender {0}", v1, v2);
|
||||
}
|
||||
8
curso_tinchicusls/prop/Cargo.toml
Normal file
8
curso_tinchicusls/prop/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "prop"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
9
curso_tinchicusls/prop/src/main.rs
Normal file
9
curso_tinchicusls/prop/src/main.rs
Normal file
@@ -0,0 +1,9 @@
|
||||
fn vec_transfer(v: Vec<i32>) {
|
||||
println!("v[0] en la función = {}", v[0]);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mivec = vec![1i32,2i32,3i32];
|
||||
vec vec_transfer(mivec);
|
||||
println!("mivec[0] es = {}", mivec[0]);
|
||||
}
|
||||
8
curso_tinchicusls/recursiva/Cargo.toml
Normal file
8
curso_tinchicusls/recursiva/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "recursiva"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
19
curso_tinchicusls/recursiva/src/main.rs
Normal file
19
curso_tinchicusls/recursiva/src/main.rs
Normal file
@@ -0,0 +1,19 @@
|
||||
fn recursivo(n: i32) {
|
||||
let mut _v: i32 = 0;
|
||||
|
||||
if n % 2 == 0 {
|
||||
_v = n / 2;
|
||||
} else {
|
||||
_v = 3 * n + 1;
|
||||
}
|
||||
|
||||
println!("{}", _v);
|
||||
|
||||
if _v != 1 {
|
||||
recursivo(_v)
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
recursivo(12)
|
||||
}
|
||||
8
curso_tinchicusls/slices/Cargo.toml
Normal file
8
curso_tinchicusls/slices/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "slices"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
16
curso_tinchicusls/slices/src/main.rs
Normal file
16
curso_tinchicusls/slices/src/main.rs
Normal file
@@ -0,0 +1,16 @@
|
||||
fn primera_palabra(s: &String) -> usize {
|
||||
let b = s.as_bytes();
|
||||
for (i, &item) in b.iter().enumerate() {
|
||||
if item == b' ' {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
s.len()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let s = String::from("Hola Mundo Cruel");
|
||||
let pos = primera_palabra(&s);
|
||||
let palabra = &s[0..pos];
|
||||
println!("{}", palabra);
|
||||
}
|
||||
8
curso_tinchicusls/tuplas/Cargo.toml
Normal file
8
curso_tinchicusls/tuplas/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "tuplas"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
28
curso_tinchicusls/tuplas/src/main.rs
Normal file
28
curso_tinchicusls/tuplas/src/main.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
fn main() {
|
||||
let (uno, dos, tres) = (1, 2, 3);
|
||||
|
||||
println!("Uno = {}", uno);
|
||||
println!("Dos = {}", dos);
|
||||
println!("Tres = {}", tres);
|
||||
|
||||
let tup = (3, "foo");
|
||||
|
||||
println!("{}", tup.0);
|
||||
|
||||
let tup: (i32, &str) = (3, "foo");
|
||||
|
||||
println!("{}", tup.0);
|
||||
|
||||
let mut _cambiar = (1.1f32, 1);
|
||||
let aesto = (3.14f32, 6);
|
||||
_cambiar = aesto;
|
||||
|
||||
println!("{}", aesto.0);
|
||||
|
||||
/* No funciona porque el tipo de dato no está en el mismo orden
|
||||
|
||||
let mut cambiar = (1.1f32, 1);
|
||||
let aesto = (6, 3.14f32);
|
||||
cambiar = aesto;
|
||||
*/
|
||||
}
|
||||
8
curso_tinchicusls/vectores/Cargo.toml
Normal file
8
curso_tinchicusls/vectores/Cargo.toml
Normal file
@@ -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]
|
||||
15
curso_tinchicusls/vectores/src/main.rs
Normal file
15
curso_tinchicusls/vectores/src/main.rs
Normal file
@@ -0,0 +1,15 @@
|
||||
// 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<i32> = 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<i64> = Vec::with_capacity(30);
|
||||
// con un iterador
|
||||
let _mi_vector5: Vec<u64> = (0..10).collect();
|
||||
|
||||
println!("{}", _mi_vector5[7])
|
||||
}
|
||||
8
curso_tinchicusls/whileloop/Cargo.toml
Normal file
8
curso_tinchicusls/whileloop/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "whileloop"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
9
curso_tinchicusls/whileloop/src/main.rs
Normal file
9
curso_tinchicusls/whileloop/src/main.rs
Normal file
@@ -0,0 +1,9 @@
|
||||
fn main() {
|
||||
let mi_arreglo = ["Lovecraft", "Poe", "Barker", "King"];
|
||||
let mut i = 0;
|
||||
|
||||
while i < mi_arreglo.len() {
|
||||
println!("{}", mi_arreglo[i]);
|
||||
i = i + 1;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user