diff --git a/codes/rust_lang/part00/.gitignore b/codes/rust_lang/part00/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..a9d37c560c6ab8d4afbf47eda643e8c42e857716 --- /dev/null +++ b/codes/rust_lang/part00/.gitignore @@ -0,0 +1,2 @@ +target +Cargo.lock diff --git a/codes/rust_lang/part00/Cargo.toml b/codes/rust_lang/part00/Cargo.toml new file mode 100644 index 0000000000000000000000000000000000000000..f56f4799d0c62156af80877f974bc5bf267c1947 --- /dev/null +++ b/codes/rust_lang/part00/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "part00" +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/codes/rust_lang/part00/src/main.rs b/codes/rust_lang/part00/src/main.rs new file mode 100644 index 0000000000000000000000000000000000000000..2420ed2de624647c87c09f10ba438c80aa35363e --- /dev/null +++ b/codes/rust_lang/part00/src/main.rs @@ -0,0 +1,33 @@ +/// Rust basics: +/// - basic types (usize, i32, str) +/// - const, let, let mut +/// - control structures (for, if) +/// - collection: arrays, indexing +/// - macros for IO and errors + +// No functions, only types used are i32, usize and [i32; SIZE]. +// Indexing of array, for and if else control structures. +// Macros: panic! for error handling, print! and println! for I/O. +// Clippy does not like the code at all. + +fn main() { + const SIZE: usize = 9; + let tab: [i32; SIZE] = [10, 32, 12, 43, 52, 53, 83, 2, 9]; + if SIZE == 0 { + panic!("Size is of tab = 0."); + } + + println!("Among the numbers in the list:"); + for i in 0..SIZE { + print!("{} ", tab[i]); + } + println!(); + + let mut min = tab[0]; + for i in 1..SIZE { + if min > tab[i] { + min = tab[i]; + } + } + println!("The minimal value is: {}", min); +}