![]() Rust Logo | |
Release Status | Maintained |
---|---|
Last Release | 1.84.1 |
Language(s) | C |
Developer(s) | The Rust Team; Originally by Graydon Hoare |
Website | rust-lang.org |
Rust, the programming language, is a multi-purpose programming language (general-purpose) that tends to prioritize concurrency of tasks, type safety, and performance. Rather than taking the typical route of other programming languages: using a method called "garbage collecting," where the program automatically frees memory, mostly prominent in programming languages such as C# or Java[1], Rust enforces memory safety, a way of preventing system memory being allocated incorrectly or using unnecessary amounts of memory at runtime[2][3] (See # Memory Safety).
Rust was heavily inspired by other programmings with its use of immutability, pattern matching, and more. It also supports Object-Orientated Programming (OOP) (See # Object-Orientated Programming in Rust). This allows for it to be used for many applications, which also includes system programming at a low-level with the use of bare-metal Rust.[4]
Rust is used in many modern day applications because of its benefits
Rust was the first programming language other than C or Assembly introduced into the Linux Kernel in December 2022 and is still currently used today.[5]
Syntax, Features, and More
Upon the installation of Rust, cargo
and other dependencies, you can generate a rust environment to work in. cargo new [Project-name]
will generate a directory with the name of [Project-Name]
that looks similar to this:
Project-Name
├─src ; Contain all code for project
| ├──main.rs ; Code is executed here
├─Cargo.toml ; Dependencies file
├─git.ignore ; Git ignore file
Hello World!
Upon opening the main.rs
file, you will be greeted with 3 lines of code:
fn main() {
println!("Hello World!")
}
fn main() { ... }
is the main function, all code written within the main()
scope will be ran normally. You can call functions from outside of the main function, for example: println!("Hello World!")
is a function that prints a new line and writes out to the terminal.[6] To declare a variable, use the let
key word to declare a non-constant variable.
fn main() {
let var_name: i32 = 64;
let mut another_var: i32 = 86;
another_var = 128;
// let declares a new variable, i32 is the type of the variable
// but is not requred, then the value is given.
// All variables end with a ";"
}
Using let
defines a new variable. You are able to label the variable however you like; but, it is a good idea to give them simple and easy names for sake of other programmers and yourself. If you need to specify the type of value a variable is, you can write out [var_name]: [type]
to declare a type, to see all types, see # Variable Types. By default, any variable defined is an immutable but using the mut
term enables the variable to mutable, influenced by functional programming. You are also allowed to use multiple let
terms to define a variable with the same name:
fn main() {
let var = 32; // Automatically defined as i32 Variable
let var = var * 2;
}
This program defines var
again by using the original value of it and multiplying it by 2, in this case, we aren't required to use the mut
term. This operation is called variable shadowing.
Variable Types
Length | Signed (-/+) | Range | Unsigned (+) | Range |
---|---|---|---|---|
1-Byte | i8
|
-128 to 127 | u8
|
0 to 255 |
2-Byte | i16
|
-32,768 to 32,767 | u16
|
0 to 65,535 |
4-Byte | i32
|
-2,147,483,648 to 2,147,483,647 | u32
|
0 to 4,294,967,295 |
8-Byte | i64
|
-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 | u64
|
0 to 18,446,744,073,709,551,615 |
16-Byte | i128
|
-170,141,183,460,469,231,731,687,303,715,884,105,728 to 170,141,183,460,469,231,731,687,303,715,884,105,727 | u128
|
0 to 340,282,366,920,938,463,463,374,607,431,768,211,455 |
arch | isize
|
Dependent on architecture of system: either i32 or i64 respectively
|
usize
|
Dependent on architecture of system: either u32 or u64 respectively
|
Object-Orientated Programming in Rust
For Context, Object-Orientated Programming is a programming paradigm designed around the concept of objects. Said objects contain 2 main parts, the attributes and their code. Attributes hold data for an object, while their code implements methods. OOP allows for inheritance of object properties through different methods[7][8]: for example C++ uses class-based inheritance while a language like Lua uses a prototype-based way for inheritance[9].[10]
Rust takes a different approach to OOP with its use of structs
, traits
, enums
, and impls
(methods).[11][12][13][14]
Similar to tuples, Structs in Rust can store multiple related values; however, structs enable for the naming of each value within itself rather than having to deconstruct the tuple. Structs are used in Rust for making attributes more global and reusable, while tuples are more preferred for short-lived variables or returning (multiple) values from functions.[12] Below shows how structs are used in code:
struct Values {
Value1: bool,
Value2: i32,
Value3: String,
// Value 4..., Value 5...
}
// Outside of the main() function, which allows it to be used anywhere
// in the file!
fn main() {
let MasterOogway: Values = Values {
Value1: true,
Value2: 64,
Value3: String::from("Use Structs you must!"),
};
}
You can give functional properties to structs with the use of impls
. Known as methods, having methods also allows for the reproducibility of code as it defines functions that use the values found in structs and is considered "implementations"; hence the key term being impl
. [8][14]
struct Cube {
Length: i32,
Width: i32,
Height: i32
}
// vvvvvv Cube implemented here vvvvvv
impl Cube {
fn Area(&self) -> i32 {
self.Length * self.Width * self.Height // This returns the Cube's Volume
}
}
fn main() {
let RubiksCube: Cube = Cube {
Length: 3,
Width: 3,
Height: 3
};
println!("Cube's Volume: {}", RubiksCube.Area())
}
The code declares a new struct with 3 values, then we implemented an Area finder function within the impl Cube
scope. We are able to use the Area()
function on any Variable with type Cube
.
Memory Safety

Memory safety refers to the practice of preventing memory-related errors, such as null pointer dereferencing, buffer overflows, and use-after-free vulnerabilities.[15] Rust enforces memory safety through its ownership system, borrowing rules, and strict type checking, eliminating the need for manual memory management typically required in languages like C and C++.[16]
Rust enforces an ownership model to manage memory at run time; Each value has a unique owner, and that ownership can be moved but not shared in a mutable sense. Upon a value exiting scope, Rust automatically deallocates it. This prevents any double-free errors and memory leaks.[15][16]
Rather than copying or moving values, Rust uses "borrowing"; this allows for functions or such to call for the value without transferring ownership. Immutable Borrowing (&T
) allows multiple immutable references to a value to coexist with each other. Only one mutable reference (&mut T
) to a value is allowed at a time.[15][17]
References
- ↑ Garbage Collection (GC), TechTarget Robert Sheldon, May 2022 (Accessed: February 15th, 2025)
- ↑ What is Ownership? # Memory and Allocation, The Rust Programming Language (Accessed: February 14th 2025)
- ↑ Memory Safety In Rust, Embedded, Jacob Beningo (Accessed: February 14th, 2025.)
- ↑ Practical System Programming for Rust Developers: Build fast and secure software for Linux/Unix systems with the help of practical examples, Prabhu Eshwarla, December 24 2020 (Accessed: February 14th, 2025)
- ↑ Git-hub: torvalds/linux: The Linux Kernel, Github 2025 (Accessed: February 15th, 2025)
- ↑ println in std - Rust std Documentation, Since 1.0.0 (Accessed: February 15th, 2025)
- ↑ Object-Orientated Programming, Alexander S. Gillers, June 2024 (Accessed: February 15th, 2025)
- ↑ 8.0 8.1 Object-oriented simulation of systems with sophisticated control, Eugene Kindler & Ivan Krivy, November 10th, 2010 (Accessed: February 15th, 2025)
- ↑ Inheritance, Lua the Programming Language, PUCRio / LabLua, Updated June 25th, 2024 (Accessed: February 15th 2025)
- ↑ Friendships and Inheritance, cplusplus.com (Unknown Publication Date!), (Accessed: February 15th, 2025)
- ↑ Traits: Defining Shared Behavior, The Rust Programming Language January 12th, 2025 (Accessed: February 15th, 2025)
- ↑ 12.0 12.1 Defining Structs, The Rust Programming Language, January 12th, 2025 (Accessed: February 15th, 2025)
- ↑ Defining an Enum, The Rust Programming Language, January 12th, 2025 (Accessed: February 15th, 2025)
- ↑ 14.0 14.1 Method Syntax, The Rust Programming Language, January 12th, 2025 (Accessed: February 15th, 2025)
- ↑ 15.0 15.1 15.2 Memory Safety Without Runtime Checks or Garbage Collection!, Dinakar Dhurjati, Sumant Kowshik, Vikram Adve, Chris Lattner, May 5th, 2003 (Accessed: February 15th, 2025)
- ↑ 16.0 16.1 Memory Safety In Rust, Ben Brosgol, January 29th, 2024 (Accessed: Feburary 15th, 2025)
- ↑ Introduction to Memory Safety in Rust: Understanding Ownership and Borrowing, Paul Amman, October 1st, 2024 (Accessed: February 15th, 2024)