Rust is a programming language that focuses on performance, safety, and concurrency. It was first released in 2010 by Mozilla and has since gained popularity for its ability to provide low-level control over system resources while preventing common programming errors like null pointer dereferences, data races.
Rust has gained popularity in blockchain and web3 development due to its emphasis on memory safety, performance, and low-level control. Its ownership system ensures secure memory management, making it suitable for smart contracts. Rust’s concurrency support is advantageous for handling multiple transactions, and its cross-platform compatibility aligns with the diverse nature of blockchain ecosystems. The active community, robust tooling, and formal verification capabilities contribute to Rust’s appeal in building secure and efficient blockchain applications.
Rust Hello World
Create the file
# hello.rs
fn main() {
println!("Hello World!");
}
Compile the binary
$ rustc hello.rs
Run it in terminal
$ ./hello
Outputs: Hello World!
Run Rust in the browser? (basic Web Server kinda like Node.js).
cargo new hello-world
cd hello-world
Add the dependencies to the Cargo.toml
[dependencies]
actix = "0.13.1"
actix-web = "4.4.0"
Update the, main.rs
use actix_web::{web, App, HttpServer, Responder};
async fn hello() -> impl Responder {
"Hello, world!"
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
App::new().service(web::resource("/").to(hello))
})
.bind("127.0.0.1:8080")?
.run()
.await
}
Run it
cargo run
Visit
http://127.0.0.1:8080
in your web browser, and you should see the"Hello, world!"
message.