This is inspired.
> Did you know you can just fork() the @rustlang compiler from your proc_macro? :D
> This is, of course, a horrible idea.
> Unfortunately rustc is multithreaded and fork() only forks one thread. We'll just assume the other threads weren't doing anything important.
> In today's rustc, this means we're only missing the main thread in the fork. But that one was only going to call exit() after joining our thread anyway, so not very important. It just means the process always exits with a success status. So instead we grep the output for "error".
Any my favorite reply:
> Is this a rust implementation of autoconf?
https://mobile.twitter.com/m_ou_se/status/136863270144881869...
A lot of people are on board with not using if/else and instead :)
match x {
true => {}
false => {}
}EDIT: quoted wrong part of parent, ignore above
> match x { true => {} false => {} }
I really like this. Pattern matching syntax is great, nice to use in place of if/else as much as possible
There's a nice alternative though, which is empty struct errors.
#[derive(Debug, thiserror::Error, displays of::Display)]
/// Frobnicating the foo failed.
struct FrobError;
The advantage is the standard advantages types use, i.e. if I want to propagate it I know this specific zero sized type has a specific meaning. It'll also show a nice message if you print it. let plural = match cases.len() > 1 {
true => "s",
false => "",
};
Of course, you'd more likely have something like let prefix = match cases.len() {
0 => "no values".to_string(),
1 => "a value".to_string(),
n => format!("{} values", n),
}; let plural = match cases.len() {
1.. => "s",
0 => "",
};
;P let plural = match cases.len() {
0 | 2.. => "s",
1 => "",
};
or something (though to be fair the original code snippet also handled "0" incorrectly -- should be "cases.len() != 1").
> What's your favourite @rustlang boolean? Option<()>, Option<Option<!>>, std::iter::Once<()>, std::fmt::Result
> tired: u16, wired: BTreeSet<BTreeSet<BTreeSet<BTreeSet<()>>>>
> What's your favourite @rustlang integer? &[()], Enumerate<Repeat<()>>, Poll<File>, *const PhantomData<usize>
@jaaaarwr> How is Vec<()> not in this poll?
> That's just the owning version of &[()], right? Why would you need to own ()s? ;)
Edit: She's also the author of inline_python!, a serious macro for interspersing code that calls python (including local variable interop), and whichever_compiles!, a joke macro that takes multiple expressions, forks the compiler (as in a fork syscall), and compiles the first one that compiles to valid rust.