$30 off During Our Annual Pro Sale. View Details »

An introduction to the Rust ecosystem

An introduction to the Rust ecosystem

Slides from my talk at Rust Warsaw #1.

Zbigniew Siciarz

May 18, 2015
Tweet

More Decks by Zbigniew Siciarz

Other Decks in Programming

Transcript

  1. Zbigniew Siciarz @zsiciarz Rust Warsaw #1 2015-05-18

    View Slide

  2. http://mickmcdee.deviantart.com/art/Fungi-ecosystem-272294806

    View Slide

  3. Zbigniew Siciarz @zsiciarz Rust Warsaw #1 2015-05-18
    The language itself

    View Slide

  4. „a systems programming
    language that runs blazingly
    fast, prevents nearly all
    segfaults, and guarantees
    thread safety.”

    View Slide

  5. I think I named it after
    fungi. rusts are amazing
    creatures.
    https://www.flickr.com/photos/basf/4837713556/

    View Slide

  6. memory
    safety
    no data races
    zero-cost
    abstractions

    View Slide

  7. rustup.sh
    distro package
    Windows installer

    View Slide

  8. https://www.flickr.com/photos/tschaut/857853764/
    https://www.flickr.com/photos/101307973@N04/13254114423/
    https://www.flickr.com/photos/101307973@N04/17099131997/

    View Slide

  9. https://github.com/brson/multirust
    manages multiple toolchains
    local overrides

    View Slide

  10. Zbigniew Siciarz @zsiciarz Rust Warsaw #1 2015-05-18
    The package manager

    View Slide

  11. fetches dependencies
    compiles code
    runs build scripts

    View Slide

  12. [package]
    name = "rustwarsaw"
    version = "0.0.1"
    authors = ["Zbigniew Siciarz
    "]
    [dependencies]
    rustc-serialize = "~0.3.14"
    docopt = "~0.6.64"
    iron = "~0.1.17"
    mount = "~0.0.7"
    staticfile = "~0.0.2"

    View Slide

  13. unit tests
    integration tests
    doctests
    examples

    View Slide

  14. #[cfg(test)]
    mod test {
    #[test]
    fn test_solution() {
    assert_eq!(2 * 21, 42);
    }
    }

    View Slide

  15. uploads package to crates.io

    View Slide

  16. /// Gets the CPU clock frequency in MHz.
    ///
    /// The underlying implementation uses several methods to discover CPU
    /// speed, including direct measurement. If all these methods fail,
    function
    /// returns `None`.
    pub fn clock_frequency() -> Option {
    // ...
    }

    View Slide

  17. rustfmt?
    future!
    guidelines
    http://doc.rust-lang.org/1.0.0/style/

    View Slide

  18. Zbigniew Siciarz @zsiciarz Rust Warsaw #1 2015-05-18
    when stdlib doesn’t cut it

    View Slide

  19. #[derive(RustcDecodable, RustcEncodable)]
    struct Movie {
    title: String,
    pub_year: usize,
    }
    let mut reader = Reader::from_file(path).unwrap();
    for row in reader.decode() {
    let movie: Movie = row.unwrap();
    println!("{}", movie.title);
    }

    View Slide

  20. fn get_content(url: &str) -> hyper::Result {
    let mut client = Client::new();
    let mut response = try!(client.get(url).send());
    let mut buf = String::new();
    try!(response.read_to_string(&mut buf));
    Ok(buf)
    }
    println!("{:?}", get_content("http://www.google.com"));

    View Slide

  21. use hyper::server::{Request, Response};
    fn hello(_: Request, res: Response) {
    res.send(b"Hello Rust Warsaw!").unwrap();
    }
    fn main () {
    hyper::Server::http(hello).listen("127.0.0.1:3000");
    }

    View Slide

  22. let mut sha = Sha256::new();
    sha.input_str("Hello world!");
    println!("{}", sha.result_str());
    let mut cipher = aes::ctr(KeySize::KeySize128, &key,
    &nonce);
    let secret = "I like Nickelback";
    let mut out: Vec =
    repeat(0u8).take(secret.len()).collect();
    cipher.process(secret.as_bytes(), &mut out[..]);
    println!("Ciphertext: {}", out.to_base64(STANDARD));

    View Slide

  23. 3D game engine
    http://www.piston.rs/
    https://github.com/PistonDevelopers
    /piston-examples

    View Slide

  24. rusqlite
    postgres
    redis
    mysql

    View Slide

  25. anymap capnproto chrono conrod
    docopt fuse gl glutin html5ever
    image iron itertools nalgebra
    openssl quickcheck rand regex
    rustache rustless sodiumoxide
    ssh2 time winapi zmq ...

    View Slide

  26. Zbigniew Siciarz @zsiciarz Rust Warsaw #1 2015-05-18
    FFI to&from other languages

    View Slide

  27. #[link(name = "cpuid")]
    extern {
    pub fn cpuid_present() -> c_int;
    pub fn cpuid_lib_version() -> *const c_char;
    pub fn cpuid_error() -> *const c_char;
    // ...
    }
    pub fn is_present() -> bool {
    unsafe {
    ffi::cpuid_present() == 1
    }
    }

    View Slide

  28. extern crate libc;
    use std::ffi::CStr;
    use libc::c_char;
    #[no_mangle]
    pub extern "C" fn count_substrings(value: *const c_char,
    substr: *const c_char) -> i32 {
    let c_value = unsafe {
    CStr::from_ptr(value).to_bytes() };
    let c_substr = unsafe {
    CStr::from_ptr(substr).to_bytes() };
    // ...
    }

    View Slide

  29. #include
    #include
    int32_t count_substrings(const char* value, const char*
    substr);
    int main() {
    printf("%d\n", count_substrings("banana", "na"));
    return 0;
    }

    View Slide

  30. import ctypes
    library_name = "../target/debug/libstringtools.so"
    stringtools = ctypes.CDLL(library_name)
    print(stringtools.count_substrings(b"banana", b"na"))
    var ffi = require('ffi');
    var library_name = '../target/debug/libstringtools.so';
    var stringtools = ffi.Library(library_name, {
    'count_substrings': ['int', ['string', 'string']]
    });
    console.log(stringtools.count_substrings("banana",
    "na"));

    View Slide

  31. https://github.com/zsiciarz/rust-ffi-stringtools
    https://github.com/alexcrichton/rust-ffi-examples
    https://doc.rust-lang.org/book/ffi.html

    View Slide

  32. Zbigniew Siciarz @zsiciarz Rust Warsaw #1 2015-05-18
    Show me the real deal

    View Slide

  33. View Slide

  34. View Slide

  35. View Slide

  36. View Slide

  37. View Slide

  38. standard library docs
    rustbyexample.com
    users.rust-lang.org
    /r/rust
    #rustlang
    zsiciarz.github.io/24daysofrust

    View Slide

  39. Zbigniew Siciarz @zsiciarz Rust Warsaw #1 2015-05-18

    View Slide

  40. Zbigniew Siciarz @zsiciarz Rust Warsaw #1 2015-05-18

    View Slide