OKdevTV Docs
Home OKdevTV
ESC
rust 1 min read 1.5 KB Raw Markdown
On this page (7)

Rust

install

Basic

  • rustc --version
  • main.rs
rust
fn main() {
    println!("Hello, world!");
}

Build & Run

  • rustc main.rs
  • ./main

cargo package manager

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

cargo how to

text
cargo new hello_world
  • Cargo.toml
text
[package]
name = "hello_world"
version = "0.1.0"
authors = ["Your Name <[email protected]>"]
edition = "2018"

[dependencies]
  • src/main.rs
rust
fn main() {
    println!("Hello, world!");
}
  • build
text
cargo build
  • run
text
./target/debug/hello_world
Hello, world!

Dependency

text
[dependencies]
time = "0.1.12"
regex = "0.1.41"
ferris-says = "0.2"
rust
use ferris_says::say;
use std::io::{stdout, BufWriter};
use regex::Regex;

fn main() {
    let re = Regex::new(r"^\d{4}-\d{2}-\d{2}$").unwrap();
    println!("Did our date match? {}", re.is_match("2014-01-01"));

    let stdout = stdout();
    let message = String::from("Hello fellow Rustaceans!");
    let width = message.chars().count();

    let mut writer = BufWriter::new(stdout.lock());
    say(message.as_bytes(), width, &mut writer).unwrap();
}

ref

rustacean