DEV Community

Alex Adam
Alex Adam

Posted on • Originally published at alexadam.dev

2 1

Getting started with Rust

Setup

On MacOS or Linux, run this command in the terminal (then follow the instructions):
More: https://www.rust-lang.org/learn/get-started

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Enter fullscreen mode Exit fullscreen mode

Get the current Rust & Cargo versions:

rustc --version
cargo --version
Enter fullscreen mode Exit fullscreen mode

Update Rust:

rustup update
Enter fullscreen mode Exit fullscreen mode

Cargo utils:

# create new project
cargo init

# compile & execute
cargo run

# build project
cargo build

# test project
cargo test

# build documentation
cargo doc

# add crate
cargo add <name>
Enter fullscreen mode Exit fullscreen mode

Source: https://www.rust-lang.org/learn/get-started

You can also install the Rust VSCode extension from here

First Project

With Cargo

Create a new folder then setup a rust project with cargo init. This command will create Cargo.toml & src/main.rs with a Hello World example. Run the project with cargo run.

mkdir new-project

cd new-project

cargo init

cargo run
Enter fullscreen mode Exit fullscreen mode

Without Cargo

Create a file named main.rs with:

fn main() {
  let hello = "Hello World";
  println!("{}", hello)
}
Enter fullscreen mode Exit fullscreen mode

Compile it with rustc main.rs then run it with ./target/debug/main (.\target\debug\hello.exe on Windows)

Image of Datadog

Master Mobile Monitoring for iOS Apps

Monitor your app’s health with real-time insights into crash-free rates, start times, and more. Optimize performance and prevent user churn by addressing critical issues like app hangs, and ANRs. Learn how to keep your iOS app running smoothly across all devices by downloading this eBook.

Get The eBook

Top comments (1)

Collapse
 
janicebarton profile image
JaniceBarton

Rust Programming Language Tutorial – How to Build a To-Do List App ? Real working love spells

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay