66 lines
1.4 KiB
Rust
66 lines
1.4 KiB
Rust
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);
|
|
}
|