From c950c6f2861c1621db371f801651af145efaa4bc Mon Sep 17 00:00:00 2001 From: clonbg Date: Tue, 23 May 2023 12:30:51 +0200 Subject: [PATCH] variables --- README.md | 3 ++- hola_mundo/src/main.rs | 47 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bdbd631..4a612c3 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ https://tinchicus.com/2022/09/26/rust-listado-del-curso-inicial/ -- https://tinchicus.com/2022/06/01/rust-usando-a-cargo/ +- https://tinchicus.com/2022/06/01/rust-usando-a-cargo/ (hola_mundo) +- https://tinchicus.com/2022/06/03/rust-strings/ diff --git a/hola_mundo/src/main.rs b/hola_mundo/src/main.rs index e7a11a9..7ffb281 100644 --- a/hola_mundo/src/main.rs +++ b/hola_mundo/src/main.rs @@ -1,3 +1,50 @@ +/// Statics, son como constantes globales +static H: i32 = 21; + +/// Main fn main() { println!("Hello, world!"); + // si no se especifica es inmutable + entero(); + enteromutable(); + // unsignet ocupa menos espacio en memoria + signet(); + unsignet(); + // const no se pueden modificar + constante(); + //static declarada fuera + println!("{H}"); + // castear (parsear) + castear(8); +} + +fn entero() { + let x = 1; + println!("{x}"); +} + +fn enteromutable() { + let mut x = 1; + x = x + 3; + println!("{x}"); +} + +fn signet() { + let sig: i32 = 2048; + println!("{sig}"); +} + +fn unsignet() { + let unsig: u32 = 2048; + println!("{unsig}"); +} + +fn constante() { + const PI: f32 = 3.14159265; + println!("{PI}"); +} + +fn castear(a: i32) { + let valor_final = a as u32; + println!("{valor_final}"); }