diff --git a/README.md b/README.md index 23eb4df..00cd65c 100644 --- a/README.md +++ b/README.md @@ -28,3 +28,4 @@ - 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) diff --git a/nuevotipo/Cargo.toml b/nuevotipo/Cargo.toml new file mode 100644 index 0000000..ffb70ba --- /dev/null +++ b/nuevotipo/Cargo.toml @@ -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] diff --git a/nuevotipo/src/main.rs b/nuevotipo/src/main.rs new file mode 100644 index 0000000..7944569 --- /dev/null +++ b/nuevotipo/src/main.rs @@ -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); +}