No description
Find a file
2017-02-25 12:57:55 -06:00
pages first examples on toml page 2017-02-25 12:43:11 -06:00
src Initial 2017-02-20 11:22:19 -08:00
tests Initial 2017-02-20 11:22:19 -08:00
.gitignore Set up pages 2017-02-25 00:38:58 -06:00
build.rs build.rs runs all the tests with new skeptic library 2017-02-25 12:19:20 -06:00
Cargo.lock first examples on toml page 2017-02-25 12:43:11 -06:00
Cargo.toml build.rs runs all the tests with new skeptic library 2017-02-25 12:19:20 -06:00
CONTRIBUTING.md Fix line breaks in contributing 2017-02-25 02:34:02 -06:00
README.md adding links for badge 2017-02-25 12:57:55 -06:00

Cookin' with Rust

A practical guide to the Rust crate ecosystem.

Recipes

Byteorder byteorder

File IO file

Command Line Parsing clap

JSON json

TOML toml

A note about error handling

Error handling in Rust is robust when done correctly, but in today's Rust it requires a fair bit of boilerplate. Because of this one often sees Rust examples filled with unwrap calls instead of proper error handling.

Since these recipes are intended to be reused as-is and encourage best practices, they set up error handling correctly, and when necessary to reduce boilerplate, they use the [error-chain] crate.

The code for this setup generally looks like:

#[macro_use]
extern crate error_chain;

mod errors {
    error_chain! {
        foreign_links {
            Io(::std::io::Error);
        }
    }
}

use errors::*;

fn main() { run().unwrap() }

fn run() -> Result<()> {
    use std::io::Write;
    let ref mut stdout = ::std::io::stdout();
    writeln!(stdout, "hello, world")?;

    Ok(())
}

This is using the error_chain! macro to define a custom Error and Result type, along with an automatic conversion from the common ::std::io::Error type. The automatic conversion makes the ? operator work

For more background on error handling in Rust, read this page of the Rust book and this blog post.

Contributing

If you'd like to make changes to the project, please see this guide.

License

MIT/Apache-2.0