HelloWorld Example in Rust Language
Here’s a simple “Hello, World!” example in Rust:
fn main() {
println!("Hello, World!");
}
Here’s what this code does:
fn main() { ... }: This is the entry point of the Rust program. Every Rust program must have amainfunction.println!("Hello, World!");: This line prints the “Hello, World!” message to the console. Theprintln!macro is used to format and print text to the standard output.
To run this code:
- Save it to a file with a
.rsextension, for example,hello.rs. - Open a terminal.
- Navigate to the directory where you saved the
hello.rsfile using thecdcommand. - Compile the Rust program using the
rustccommand:
rustc hello.rs
- Run the compiled program:
./hello
You should see the “Hello, World!” message printed to the console. This is a basic example of a Rust program, and it demonstrates how to define a main functio
Discover more from PiEmbSysTech - Embedded Systems & VLSI Lab
Subscribe to get the latest posts sent to your email.



