This file contains hidden or 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(unsafe_destructor, macro_rules)] | |
#[macro_escape] mod fat { | |
use std::mem::transmute; | |
use std::raw::TraitObject; | |
#[unsafe_no_drop_flag] | |
pub struct SlimPtr<Sized? T> { | |
ptr: *mut *mut () | |
} |
This file contains hidden or 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
use std::util::replace; | |
enum List<T> { | |
Cons(T, ~List<T>), | |
Nil | |
} | |
impl<T> List<T> { | |
fn prepend(&mut self, elem: T) { | |
*self = Cons(elem, ~replace(self, Nil)); |
This file contains hidden or 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
use std::io::IoResult; | |
struct SBuf<T> { | |
br: T, | |
current: String | |
} | |
impl<T: Buffer> SBuf<T> { | |
This file contains hidden or 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
#![crate_type="lib"] | |
/// increments | |
/// | |
/// ``` | |
/// let x = bar(41); | |
/// assert_eq!(x, 42); | |
/// ``` | |
pub fn bar(x: int) -> int { x + 1 } |
This file contains hidden or 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
use std::collections::HashMap; | |
use std::path::Path; | |
use std::io::fs::File; | |
use std::io::BufferedReader; | |
fn main() { | |
let path = Path::new("potop2.txt"); | |
let reader = File::open(&path).unwrap(); | |
let mut reader = BufferedReader::new(reader); |
This file contains hidden or 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 Iterator<T> { | |
//... | |
fn len(self) { // not &mut self ! | |
match self.size_hint() { | |
(bot, Some(up)) if bot == up => bot, | |
_ => self.fold(0, |cnt, _x| cnt + 1) | |
} | |
} | |
} |
This file contains hidden or 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
## Simple syntax highlighter for rust | |
## | |
syntax "rust" "\.rs$" | |
## keywords | |
color brightgreen "\<(as|be|break|copy|else|enum|extern|false|fn|for|if|impl|let|loop|match|mod|mut|priv|pub|ref|return|static|struct|super|true|trait|type|unsafe|use|while|yield|in|crate|continue|box)\>" | |
color brightwhite "\<(self)\>" | |
color cyan "\<(mut)\>" | |
## basic types |
This file contains hidden or 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 List_ { | |
Cons(int, ~List_), | |
Nil | |
} | |
struct List(~List_); | |
impl List { | |
fn prepend(&mut self, x : int) { | |
let List(old) = self; // I have no idea, how to write this line |
This file contains hidden or 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 List { | |
Cons(int, ~List), | |
Nil | |
} | |
impl List { | |
fn prepend(~self, x : int) -> ~List { | |
~Cons(x, self) | |
} | |
} |
This file contains hidden or 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
#include <cstdio> | |
#include <thread> | |
#include <future> | |
#include <mutex> | |
using namespace std; | |
struct Obiekt { | |
int x; | |
void f() { printf("Hej %d!\n", x); } | |
}; |