tuple struct

This commit is contained in:
2023-06-22 14:46:17 +02:00
parent ce7dd49028
commit 7d9450217c
3 changed files with 20 additions and 0 deletions

View File

@@ -28,3 +28,4 @@
- https://tinchicus.com/2022/07/12/rust-memoria-estatica/ (ejemplo03) - https://tinchicus.com/2022/07/12/rust-memoria-estatica/ (ejemplo03)
- https://tinchicus.com/2022/07/13/rust-struct/ (estructura) - 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/14/rust-struct-en-multiples-archivos/ (estructura2)
- https://tinchicus.com/2022/07/15/rust-tuple-struct/ (nuevotipo)

8
nuevotipo/Cargo.toml Normal file
View 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
View 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);
}