Upgrade to Pro — share decks privately, control downloads, hide ads and more …

talk about rust

Avatar for Lazy Eval Lazy Eval
November 24, 2015
42

talk about rust

Avatar for Lazy Eval

Lazy Eval

November 24, 2015
Tweet

Transcript

  1. Rust Rust is a systems programming language focused on three

    goals: safety, speed, and concurrency. 1
  2. Primitive Types • Booleans • char • Numeric types •

    Arrays • Slices • Tuples • str • Functions 2
  3. Syntax let a = 1; //immutable let mut b =

    2; //mutable fn foo(x :int) -> int { x } pub struct Vec<T> { buf: RawVec<T>, len: usize, } pub trait Debug { fn fmt(&self, &mut Formatter) -> Result<(), Error>; } impl<T: fmt::Debug> fmt::Debug for Vec<T> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Debug::fmt(&**self, f) } } 3
  4. Option Rust's pointer types must always point to a valid

    location; there are no "null" pointers. Instead, Rust has optional pointers, like the optional owned box, Option<Box<T>>. let msg = Some("howdy"); // Take a reference to the contained string match msg { Some(ref m) => println!("{}", *m), None => (), } // Remove the contained string, destroying the Option let unwrapped_msg = match msg { Some(m) => m, None => "default message", };
  5. Borrow pub trait Borrow<Borrowed> where Borrowed: ?Sized { fn borrow(&self)

    -> &Borrowed; } impl<T: ?Sized> borrow::Borrow<T> for Arc<T> { fn borrow(&self) -> &T { &**self } }