Mutability
Values in rust are immutable by default and must be tagged as being mutable(if needed).
Below is the Rust program to implement Mutability:
fn main() {
let x = 2;
// It will show an error
x = 9;
println!("{}", x);
}
The above example will show an error because we have not tagged it as mutable.
fn main() {
let mut x = 2;
// This will work fine
x = 9;
println!("{}", x);
}
Output:
9
This will work fine as we have tagged it as being mutable. As in this case we are explicitly mutating it.
Introduction to Rust Programming Language
Rust is a blazing fast and memory-efficient static compiled language with a rich type system and ownership model. It can be used to power performance-critical services while guaranteeing memory-safety and thread-safety, empowering developers to debug at compile-time. In addition to that Rust has great documentation and a user-friendly compiler with top-end tools like integrated package managers and multi-editor with features like type inspection and auto-completion. Rust prevents all the crashes, and, interestingly, Rust is safe by default like JavaScript, Ruby, and Python. This is much more powerful than C/C++ because we cannot write the wrong parallel code you can never see fault in rust. It is very fast in representing a lot of programming paradigms very well.
But the question arises as there are already so many programming languages like Python, C++, Java, etc, then why the need for developing a new programming language? The answer to this is the other programming languages have a lot of control over the hardware that you are running, like, you can optimize it well, translate directly to assembly code, but it’s not very safe.
So rust provides us all the controls that we can have and all the levels of security that we can achieve.
Rust is using Rust which means that all the standard compiler libraries are written in rust; there is a bit of use of the C programming language but most of it is Rust. The big project of Rust is “servo”, It is a project to write out the totally parallel layout engine like Gecko in Firefox or WebKit in Safari.
Servo built the layout engine, something to render HTML from bottom to top.
Become a Rust Professional Learn the fundamentals of Rust programming, practice its applications in web and game development, and get ready for coding interviews with Educative’s interactive skill path Become a Rust Professional. Sign up at Educative.io with the code GEEKS10 to save 10% on your subscription
Table of Content
- Functions in Rust
- Concept of Ownership
- Concept of Borrowing
- Memory management in Rust
- Mutability
- Structure in Rust
- Tuple
- Rust Type System
- Advantages of Rust
- Disadvantages of Rust