tuple struct
This commit is contained in:
8
nuevotipo/Cargo.toml
Normal file
8
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
nuevotipo/src/main.rs
Normal file
11
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);
|
||||
}
|
||||
Reference in New Issue
Block a user