From bb80384d53f41e97d43a84f7d9962bbc78b1b909 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20du=20Garage=20Num=C3=A9rique?= Date: Wed, 6 May 2026 22:42:36 +0200 Subject: [PATCH] v0.0.2 chap3.2 datatypes scalar --- datatypes/.gitignore | 1 + datatypes/Cargo.lock | 7 ++++++ datatypes/Cargo.toml | 6 +++++ datatypes/src/main.rs | 52 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+) create mode 100644 datatypes/.gitignore create mode 100644 datatypes/Cargo.lock create mode 100644 datatypes/Cargo.toml create mode 100644 datatypes/src/main.rs diff --git a/datatypes/.gitignore b/datatypes/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/datatypes/.gitignore @@ -0,0 +1 @@ +/target diff --git a/datatypes/Cargo.lock b/datatypes/Cargo.lock new file mode 100644 index 0000000..397170f --- /dev/null +++ b/datatypes/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "datatypes" +version = "0.1.0" diff --git a/datatypes/Cargo.toml b/datatypes/Cargo.toml new file mode 100644 index 0000000..a3d5cf3 --- /dev/null +++ b/datatypes/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "datatypes" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/datatypes/src/main.rs b/datatypes/src/main.rs new file mode 100644 index 0000000..391909c --- /dev/null +++ b/datatypes/src/main.rs @@ -0,0 +1,52 @@ +fn main() { + println!(" +Rust is a statically typed language. + +There are 2 subsets of datatypes: scalar and compound. + +1/ Scalar types + +Scalar types represents a single value. + +Rust has: integers, floating-point numbers, +Boolean and characters + +1.1/ integers can be signed or unsigned and + size from 8 bits to 128 bits, + or have a size depending of the arch. + Default type is i32. + i8 ranges from -(2⁷) to 2⁷ - 1, ie -128 to 127 + + let x: u32 = 3000; + let x: i32 = -230_000; // equals -230000 + let x: u16 = 0xff; // hexa form for 255 + let x: usize = 0b1111_0000; // binary form + let x: u8 = b'A'; // byte form only u8 + +1.2/ Floating-point types can be f32 or f64, + default to f64: + + let x = 2.0; // f64 + let x: f32 = 3.0; // f32 + + Support basic mathematical operations: + + let sum = 3.4 + 5.6; + let difference = 90_000 - 289; + let product = 4 * 30; + let quotient = 56.7 / 32.2; + let truncated = -5 / 3; + let remainder = 43 % 5; + +1.3/ Boolean: + + let t: bool = true; + +1.4/ A `char` is 4 bytes in rust and covers unicode: + + let mut c: char = 'z' // note the single quote + c = '🤗' + + "); +} +