Month: April 2025
-
3 Statements and Expressions in Rust
3 Statements and Expressions in Rust The same variable name can be defined multiple times The inner scope defines a new variable x that shadows the outer x. As a result, the value of x defined within the inner scope does not affect the value of the x in the outer scope The result of…
-
2 Union vs. Enum in Rust: Understanding Memory Layout
2 Union vs. Enum in Rust: Understanding Memory Layout mem::size_of::<MyUnion>() -> 8 bytes The size is based on the largest member. mem::size_of::<MyUnion>() -> 24 bytes The size of determined by the size of the largest vaiant plus the size of the additional identifier(tag) and then aligned to the required memory alignment. The size of the…