- Option: "None is a totally valid result, usually found in data structures"
- unwrap(): YOLO use in prototyping
- expect(...): to indicate the reason you believe None is impossible (or a contract violation for the method)
- Result: 😱 "Errors are unexpected but not bugs; the decision for how to handle them is up to the caller"
- unwrap(): YOLO "I'm an app and don't know how to handle this error -- I'm fine if the whole process aborts"
- try! / ?: "Leave the decision about how to handle this error to the caller; they have more information"
- match / catch: "I'm going to handle the error right here right now"
- panic!: ☠ "The error is a bug and can't be recovered from. Game over man. Rust is allowed to abort the process if it wants"
use std::io; | |
use std::io::prelude::*; | |
fn main() { | |
loop { | |
let r = get_input("Enter the first number: ") | |
.and_then(|x| get_input("Enter the second number: ") | |
.and_then(|y| get_input("Enter the third number: ") | |
.and_then(|z| Ok(x + y + z)))); |
use std::collections::BTreeMap; | |
// Why we might want multiple lifetimes... | |
// We want this structure to be trivially copyable as we pass it | |
// around and modify the position. | |
#[derive(Copy, Clone)] | |
struct Cache<'d, 's: 'd> { | |
data: &'d BTreeMap<usize, &'s str>, | |
position: usize, |
enum Meal { | |
TvDinner, | |
HomeCooked { healthy: bool }, | |
} | |
let lunch = Meal::TvDinner; | |
let dinner = Meal::HomeCooked { healthy: true }; | |
match lunch { | |
Meal::TvDinner => println!("Eating a TV dinner"), |
// The error is that there's an unused generic G declared... | |
fn foo<G>() -> String { | |
String::from("hi") | |
} | |
fn main() { | |
println!("{}", foo()); | |
// ^ but here is where the error message points to: | |
// error: unable to infer enough type information about `_`; type annotations or generic parameter binding required [E0282] |
I'm not a C# dev and haven't gotten one to look at this yet, it might be very very wrong.
The goal of this is to have an easily-scannable reference for the most common syntax idioms in C# and Rust so that programmers most comfortable with C# can quickly get through the syntax differences and feel like they could read and write basic Rust programs.
What do you think? Does this meet its goal? If not, why not?
http://rstat.us is dead. Long live rstat.us?
Hey everyone,
As you may have noticed, I have been a Bad Open Source Maintainer and I have not been doing even the minimum amount of maintenance on either the codebase or the main node living at http://rstat.us.
Wilkie has been poking around the code lately, and I'm encouraged because he's got his own node running.
Which brings me to the point of this email-- growing http://rstat.us was never the dream of this project, the dream was to have everyone owning and operating their own nodes that would talk to each other.
# Add this to your .bashrc: | |
source ~/.test_completion.sh |
module Capybara::Poltergeist | |
class Client | |
private | |
def redirect_stdout | |
prev = STDOUT.dup | |
prev.autoclose = false | |
$stdout = @write_io | |
STDOUT.reopen(@write_io) | |
prev = STDERR.dup |
# How to find files that have spaces around attribute delimiters | |
git ls-files *.slim* | xargs -I {} slimrb -c {} | grep "spaces around attribute delimiters" |