Skip to content

Instantly share code, notes, and snippets.

View williamyaoh's full-sized avatar

William Yao williamyaoh

View GitHub Profile
@williamyaoh
williamyaoh / error-handling.md
Last active April 2, 2018 19:28
Example of how Rust gives static guarantees that you're handling errors correctly

Rust has a built-in generic type called Option<T>, so a value of type Option<i32> can be read as "I either have a valid 32-bit integer, or nothing." Using it as a return type tells your callers that you might fail, and makes sure that they handle that possibility correctly.

pub fn maybe_divide(x: i32, y: i32) -> Option<i32>

would be the signature of a function which might fail to produce a value

@williamyaoh
williamyaoh / fetch-tar.nix
Created April 9, 2017 01:55
Nix fetchTarball with SHA256 sum checking
# We expect the tarball to only contain a single directory, the
# same way that the builtin `fetchTarball' does.
{ stdenv, nix }:
{ url,
# Name we label this derivation with.
name,
# Hash of *extracted output directory*,
# as generated by `nix-hash --type sha256 --base32'.
@williamyaoh
williamyaoh / rfc_documentation_status.md
Last active April 4, 2017 21:24 — forked from chriskrycho/rfc_documentation_status.md
Status (as best it is known) of RFCs not yet documented or tracked in https://github.com/rust-lang-nursery/reference/issues/9

With full credit where it is due: to @EH2406, who put the original together (here). Note that I'm doing a quick pass and confirming each of these as I get to them.

Need documentation - * means this is (should be) in the expressions chapter rewrite

  • #0090: lexical-syntax-simplification

    Lexical syntax is already documented in the grammar reference, but isn't up-to-date with RFC 0090. Since there's already a lexical syntax section in the Rust Reference, probably just add this to the Reference instead.