This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name="bob" | |
version="0.0.1" | |
authors=["insaneinside"] | |
[lib] | |
name="bob" | |
path="lib.rs" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name="bob" | |
version="0.0.1" | |
[lib] | |
name="bob" | |
path="lib.rs" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Tremendously hacky measurement of the arity of function signatures in the Rust repository: | |
0 12919 48.10% | |
1 7703 28.68% | |
2 3388 12.61% | |
3 1544 5.74% | |
4 705 2.62% | |
5 345 1.28% | |
6 144 0.53% | |
7 58 0.21% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[deriving(PartialEq)] | |
enum Ordering { | |
Less, | |
Equal, | |
Greater, | |
} | |
fn cmp(a: int, b: int) -> Ordering { | |
if a < b { Less } | |
else if a > b { Greater } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait HasArea { | |
fn area(&self) -> f64; | |
} | |
trait RectangularArea: HasArea { | |
fn area(&self) -> f64 { | |
self.length() * self.width() | |
} | |
fn length(&self) -> f64; | |
fn width(&self) -> f64; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<std macros>:2:59: 2:65 error: mismatched types: expected `()`, found `core::result::Result<<generic #9>,()>` (expected (), found enum core::result::Result) | |
<std macros>:2 ($e:expr) => (match $e { Ok(e) => e, Err(e) => return Err(e) }) | |
^~~~~~ | |
<std macros>:1:1: 3:2 note: in expansion of try! | |
try.rs:2:13: 2:25 note: expansion site |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait Foo { | |
fn new() -> Self; | |
} | |
struct Bar(int, int); | |
impl Foo for Bar { | |
fn new() -> Bar { | |
Bar(1, 2) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(macro_rules)] | |
macro_rules! iota( | |
($($thing:expr),+) => (iota_expr!(1, $($thing),*)); | |
($($thing:pat),+) => (iota_pat!(1, $($thing),*)); | |
() => (()); | |
) | |
macro_rules! iota_expr( | |
($id:expr, $head:expr, $($tail:expr),*) => ({ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(macro_rules)] | |
macro_rules! vec_new( | |
($($e:expr),*) => ({ | |
// leading _ to allow empty construction without a warning. | |
let mut _temp = ::std::vec::Vec::with_capacity(arity!($($e),*)); | |
$(_temp.push($e);)* | |
_temp | |
}); | |
($($e:expr),+,) => (vec_new!($($e),+)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(macro_rules)] | |
macro_rules! foo { | |
($id:expr, $head:expr, $($tail:expr),+) => ({ | |
foo!($id, $head); | |
foo!($id+1, $($tail),+); | |
}); | |
($id:expr, $var:expr) => ({ | |
println!(" {} = {},", $var, $id); | |
}); |