funciones y metodos - struct e impl

This commit is contained in:
2023-06-04 12:50:23 +02:00
parent a077149208
commit 327e1279fc
2 changed files with 22 additions and 0 deletions

8
ejemplo01/Cargo.toml Normal file
View 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
ejemplo01/src/main.rs Normal file
View 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)
}