copy trait
This commit is contained in:
@@ -32,3 +32,4 @@
|
|||||||
- https://tinchicus.com/2022/07/18/rust-enum/ (enums)
|
- 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/19/rust-patrones-y-coincidencias/ (iflet)
|
||||||
- https://tinchicus.com/2022/07/20/rust-ownership/ (prop)
|
- https://tinchicus.com/2022/07/20/rust-ownership/ (prop)
|
||||||
|
- https://tinchicus.com/2022/07/21/rust-copy-trait/ (copiari32, copiar)
|
||||||
|
|||||||
8
copiar/Cargo.toml
Normal file
8
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
copiar/src/main.rs
Normal file
12
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
copiari32/Cargo.toml
Normal file
8
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
copiari32/src/main.rs
Normal file
9
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);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user