diff --git a/3-99 Research/Rust/Chapter 3 - Common Programming Concepts.md b/3-99 Research/Rust/Chapter 3 - Common Programming Concepts.md index d8fef8eb..729be546 100644 --- a/3-99 Research/Rust/Chapter 3 - Common Programming Concepts.md +++ b/3-99 Research/Rust/Chapter 3 - Common Programming Concepts.md @@ -61,6 +61,34 @@ fn main() { Constants are by convention written in UPPER_CAMEL_CASE. # 3.2 Data Types +Rust is a statically typed language. Variables in Rust must have their types +known at compile time, or else the compilation will fail. A lot of times types +can be inferred, but this is not possible for cases where there are multiple +possible types. + +For these cases, the type must be annotated, like this: +```rust +let annotated: str = "This one is annotated!"; +let not_annotated = "This one is not!"; +``` + +## Scalar Types +Scalar types are those that only take on one object. Examples in Rust are +integers, characters, booleans, and floating-point numbers. + +Integers can be signed or unsigned, with different levels of bit resolution, +up to 128 bits. That being said, there is an 'arch' length that is the size of +the operating system. This is used with `isize` and `usize`. Signed integers are +stored with two's complement. + +Numbers can also be written in differnet formats, including decimals (with _ +escapes), hex values, octal values, binary values, or even as a byte(b'A'). + +>[!note] A special note about *integer overflow*. +> Rust code compiled and ran in debug mode will have checks for integer +> overflow, causing the code to panic at runtime if an overflow occurs. +> Production code compiled with the `--release` flag will NOT panic however, +> but instead will wrap around to the first value in the possible range. # 3.3 Functions diff --git a/3-99 Research/Rust/guessing_game/target/.rustc_info.json b/3-99 Research/Rust/guessing_game/target/.rustc_info.json index c4dff84a..2e6b8ece 100644 --- a/3-99 Research/Rust/guessing_game/target/.rustc_info.json +++ b/3-99 Research/Rust/guessing_game/target/.rustc_info.json @@ -1 +1 @@ -{"rustc_fingerprint":9317237865466217508,"outputs":{"1185988223601034215":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/home/danesabo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu\noff\npacked\nunpacked\n___\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_abi=\"\"\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"unknown\"\nunix\n","stderr":""},"15611795083382425170":{"success":true,"status":"","code":0,"stdout":"rustc 1.84.0 (9fc6b4312 2025-01-07)\nbinary: rustc\ncommit-hash: 9fc6b43126469e3858e2fe86cafb4f0fd5068869\ncommit-date: 2025-01-07\nhost: x86_64-unknown-linux-gnu\nrelease: 1.84.0\nLLVM version: 19.1.5\n","stderr":""}},"successes":{}} \ No newline at end of file +{"rustc_fingerprint":416372215023924338,"outputs":{"1185988223601034215":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/home/danesabo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu\noff\npacked\nunpacked\n___\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_abi=\"\"\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"unknown\"\nunix\n","stderr":""},"15611795083382425170":{"success":true,"status":"","code":0,"stdout":"rustc 1.84.1 (e71f9a9a9 2025-01-27)\nbinary: rustc\ncommit-hash: e71f9a9a98b0faf423844bf0ba7438f29dc27d58\ncommit-date: 2025-01-27\nhost: x86_64-unknown-linux-gnu\nrelease: 1.84.1\nLLVM version: 19.1.5\n","stderr":""}},"successes":{}} \ No newline at end of file