Skip to content

gcamerli/rust-play

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rust play

Collection of rust programs from the official book The Rust Programming Language.

TOC

  1. Setup
  2. Usage
  3. Playground
  4. Docker
  5. Resources
  6. Doc
  7. License

Setup

To start to use rust on UNIX-like system it's enough to run:

$ curl https://sh.rustup.rs -sSf | sh

rustup will install the latest stable version. Then to add cargo to your system PATH, include the following line to your rc file:

export PATH="$HOME/.cargo/bin:$PATH"

Usage

Firstly check if rust and cargo are properly set:

$ rustc -V; cargo -V

If all is good the output will show the version of both binaries.

🦀

There are 2 different ways to compile rust programs.

Rustc

The 1st using the compiler rustc. So starting from a classic hello.rs:

fn main() {
    println!("Hello, world!");
}

To compile our function:

$ rustc hello.rs

This will create a binary called hello, that will print the string Hello, World!.

Cargo

The 2nd using the package manager cargo. So running:

$ cargo new hello_world

we can create our first rust package and have a structure like the following:

$ cd hello_world
$ tree .
.
├── Cargo.toml
└── src
    └── main.rs

1 directory, 2 files

To interact with this package there are several options:

$ cargo check # To check if it is error-proof
$ cargo build # To compile it and store the binary under target/debug
$ cargo build --release # To compile it and store the binary under target/release
$ cargo run # To run the binary
$ cargo update # To update the version of all the dependencies

Playground

cup

Hack without fear!

Docker

The official docker images:

Resources

Doc

License

This work is unlicensed under the terms of Unlicense.

Releases

No releases published

Packages

No packages published

Languages