diff --git a/README.md b/README.md index 501da81..b2abb6e 100644 --- a/README.md +++ b/README.md @@ -9,4 +9,5 @@ https://tinchicus.com/2022/09/26/rust-listado-del-curso-inicial/ - https://tinchicus.com/2022/06/10/rust-slice/ (slices) - https://tinchicus.com/2022/06/13/rust-pasando-valores/ (porvalor y porreferencia) - https://tinchicus.com/2022/06/14/rust-la-libreria-std/ -- https://tinchicus.com/2022/06/15/rust-println/ (println) \ No newline at end of file +- https://tinchicus.com/2022/06/15/rust-println/ (println) +- https://tinchicus.com/2022/06/16/rust-format/ (format) \ No newline at end of file diff --git a/format/Cargo.toml b/format/Cargo.toml new file mode 100644 index 0000000..9f82067 --- /dev/null +++ b/format/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "format" +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/format/src/main.rs b/format/src/main.rs new file mode 100644 index 0000000..e16a955 --- /dev/null +++ b/format/src/main.rs @@ -0,0 +1,23 @@ +fn main() { + println!("Hello, world!"); + let mut visual = format!("{} {}", 23, 89); + println!("{}", visual); + visual = format!("{} {1} {} {0}", "Hola", "Mundo"); + println!("{}", visual); + visual = format!("{t} {a} {b} {a}", a = "Hola", b = "Mundo", t = 23); + println!("{}", visual); + visual = format!("{:.4}", 3.1415927); + println!("{}", visual); + + let v1 = format!("{:.3}", 3.1415927); + let v2 = format!("{:b}", 55); + let v3 = format!("{:+}!", 5); + let v4 = format!("{:x}", 95); + let v5 = format!("{:#x}", 95); + + println!("{}", v1); + println!("{}", v2); + println!("{}", v3); + println!("{}", v4); + println!("{}", v5); +}