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
//! | |
//! >rustc --version | |
//! rustc 0.10-pre (ee8f45e 2014-02-18 13:41:49 -0800) | |
//! | |
//! In this example we will implement Any for a trait pointer. | |
//! This is useful when we want to design an Entity/Component system | |
//! that is extensible beyond the library. | |
//! | |
//! As example we have two objects 'Player' and 'Enemy'. | |
//! Both implement the trait 'Entity' which is used 90% of the time. |
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
//! rustc 0.10-pre (ee8f45e 2014-02-18 13:41:49 -0800) | |
//! | |
//! Before you bite my head off, this is NOT a recommend way of organizing code! | |
//! It is only a demonstration what you can do in Rust! (wish I put this comment in earlier) | |
//! My intention with this example is to show new people the features of the module system. | |
//! | |
//! The module system in Rust gives you precise control | |
//! over the interface when writing libraries. | |
//! You can write the layout independent of how you organize the code! | |
//! In this example two different conventions are explored. |
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
rustc 0.10-pre (0a5138c 2014-03-04 13:16:41 -0800) | |
/// A struct with borrowed pointer to a closure. | |
/// This is to be able to reuse the closure then struct runs out of scope. | |
pub struct Test<'a> { | |
f: &'a 'a || | |
} | |
impl<'a> Test<'a> { |
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
rustc 0.10-pre (0a5138c 2014-03-04 13:16:41 -0800) | |
pub trait Expr<'a, T> { | |
fn then(&'a self, f: &'a 'a ||) -> T; | |
} | |
impl<'a> Expr<'a, ()> for () { | |
fn then(&'a self, f: &'a 'a ||) -> () { | |
(*f)(); |
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
#!/bin/sh | |
while true; do | |
echo -n " > " | |
read line | |
TMP=`mktemp` | |
rustc - -o $TMP <<EOF | |
#[feature(globs, macro_rules, struct_variant)]; | |
// extern mod extra; | |
fn main() { |
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
/** | |
* cairo_show_text: | |
* @cr: a cairo context | |
* @utf8: a NUL-terminated string of text encoded in UTF-8, or %NULL | |
* | |
* A drawing operator that generates the shape from a string of UTF-8 | |
* characters, rendered according to the current font_face, font_size | |
* (font_matrix), and font_options. | |
* |
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
//! Chain macro in Rust | |
//! | |
//! A typical usage is to avoid nested match expressions. | |
//! | |
//! Supports: | |
//! - Pattern matching | |
//! - Or expressions (A | B => ...) | |
//! - Guarded statements (x if <cond> => ...) | |
//! - Implicit else (requires all arms to return same type) |
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
let x = Some(1); | |
let y = Some(2); | |
let z = monad!( | |
None { | |
_ => x, | |
Some(x) => y, | |
Some(y) => Some(x+y) | |
} | |
); | |
assert_eq!(z, Some(3)); |
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
enum Void {} | |
enum Foo<T, U> { | |
A(int) for T = (), U = () | |
} |
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
fn insert_text(text: &mut HashMap<&'static str, &'static str>) { | |
let text: Vec<&'static str> = vec!(include!("text.rs")); | |
for chunk in text.as_slice().chunks(2) { | |
let id: &'static str = *chunk.get(0).unwrap(); | |
let txt: &'static str = *chunk.get(1).unwrap(); | |
text.insert(id, txt); | |
} | |
} | |