.rs

feature

  • zero-cost abstractions
  • move semantics
  • guaranteed memory safety
  • threads without data races
  • trait-based generics
  • pattern matching

Fast

  • LLVM
  • Compile to binary
  • no GC
  • minimal runtime

Prevent segfaults

  • No dangling pointer
  • No null pointer
  • No segfault

thread safety

  • No data race
    • Ownership guarantee

  • hard to compile

Cargo

  • The Rust package manager
    • downloads dependencies

Rustup

  • Rust toolchain installer
    • stable
    • beta
    • nightly

playground

Hello, rust

`
fn main(){
println!("Hello World");
}
`

`
fn main() {
let language = "rust";
println!("Hello, {}", language);
}
`

`
fn main() {
println!("Factorial: {}", factorial(5));
}
fn factorial(i: u64) -> u64 {
let mut acc = 1;
for num in 2..i+1 {
acc *= num;
}
acc
}
`

Rust

  • statement & expression
    • statement : no return value
      • let statement
    • expression : evaluate to a resulting value
      • operation
      • calling a function
      • calling a macro
      • block

ownership(소유권)

  • enables memory safety guarantees without a garbage collector.

Ownership Rules

  • Each value in Rust has a variable that's called its owner.
  • There can only be one owner at a time.
  • When the owner goes out of scope, the value will be dropped. -> lifetime
  • At any given time, you can have either one mutable reference or any number of immutable references.
  • References must always be valid.
Retrieved from http://wiki.zeropage.org/wiki.php/데블스캠프2018/RS
last modified 2021-02-07 05:29:19