Let's try creating a simple program using basic development tools.
- Prerequisite: Rust development environment setup
Creating the First Program in Rust
You can scaffold a simple "binary" app in Rust
using either cargo new
or cargo init
:
$ cargo new first-program && cd $_
Or,
$ mkdir first-program && cd $_
$ cargo init
They end up with the same boilerplate code.
$ ls
Cargo.toml src
Cargo.toml
[package]
name = "first-program"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
src/main.rs
fn main() {
println!("Hello, world!");
}
$ cargo run
Compiling first-program v0.1.0 (/home/harry/Projects/codeandtips/code/rust/first-program)
Finished dev [unoptimized + debuginfo] target(s) in 0.94s
Running `target/debug/first-program`
Hello, world!
$ cargo -q run
Hello, world!
$ cargo build
Compiling first-program v0.1.0 (/home/harry/Projects/codeandtips/code/rust/first-program)
Finished dev [unoptimized + debuginfo] target(s) in 0.53s
$ ./target/debug/first-program
Hello, world!
C C++ C# Clojure Crystal D Dart Erlang F# Go Haskell Java Javascript Julia Kotlin Lua Python Scala Swift Typescript