Skip to content

Latest commit

 

History

History
46 lines (36 loc) · 1.79 KB

00_intro.md

File metadata and controls

46 lines (36 loc) · 1.79 KB

Intro

Rust is a compiled, statically and strongly typed language. Main features:

  • memory safety
  • low-level performance
  • zero-cost abstractions
  • non-nullable references

Install Rust via rustup, which installs all Rust tools and cargo — Rust's official package manager and orchestration tool.

For a playground during learning, run cargo new playground, edit main.rs and run by cargo run in the project root directory.

Constructs

  • primitives like i32, f64, bool
  • arrays are fixed-size collections of values of the same type, [i32; 100]
  • tuples are collections of values of different types, (i32, i32, &str)
  • references allow borrowing data, &value
  • slices offer referencing data sequences with a variable size, [T], str
  • structs hold related data and define related methods , vector.normalize()
  • enums define variants of types, Result<T, E> and its Ok(T), Err(E)
  • generics allow parameters of different types Vec<T>
  • traits define behavior that types have like ToString
  • DSTs are types with size not known at compile-time, dyn Trait, [T] , str
  • lifetimes ensure data validity, 'static,'a
  • closures are anonymous functions that capture their context, |x| x * 2
  • attributes are metadata for crates, modules or items, #[attr] , #![crate_attr]
  • macros for metaprogramming, declarative and procedural, println!("a macro") or #[derive(Debug)]

Comments

Comments are specified after //. No special multiline syntax.

Conventions

  • snake_case for crates, but prefer single-word
  • snake_case for functions, variables, macros and lifetimes
  • PascalCase for enums, structs, generics and traits
  • SCREAMING_SNAKE_CASE for constants and statics