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
#include <cstdio> | |
struct _Ms { int x; }; | |
struct _Us { int x; }; | |
constexpr _Ms operator "" ms(long long unsigned x) { return {(int)x}; } | |
constexpr _Us operator"" us(long long unsigned x) { return {(int)x}; } | |
void fun(_Ms x) { printf("%d milisekund\n", x.x); } | |
void fun(_Us x) { printf("%d mikrosekund\n", x.x); } |
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
#define F_CPU 12000000UL | |
#include <krdln/port.h> | |
int main() { | |
Output<A::Pin<0>> led; | |
Output<A::Pin<2>, false> err; // false: "on" level is 0V | |
Button<C::Pin<3>> but; // automagic pullup, yay! | |
int const T = 300; | |
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
use std::rt::io::{stdout,Writer}; | |
fn main() { | |
print("Hello"); | |
stdout().write(" World".as_bytes()); | |
println("!"); | |
} |
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
use std::rt::io::Writer; | |
use std::rt::io::stdio::with_task_stdout; | |
struct MagicWriter(); | |
impl Writer for MagicWriter { | |
fn write(&mut self, buf: &[u8]) { | |
do with_task_stdout |o| { o.write(buf); } | |
} | |
fn flush(&mut self) { | |
do with_task_stdout |o| { o.flush(); } |
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
#include <sstream> | |
#include <iostream> | |
#include <string> | |
using namespace std; | |
string ss2s(ostream const& os) { | |
return static_cast<stringstream const&>(os).str(); | |
} | |
int 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
#include <cstdio> | |
#include <thread> | |
#include <future> | |
#include <mutex> | |
using namespace std; | |
struct Obiekt { | |
int x; | |
void f() { printf("Hej %d!\n", x); } | |
}; |
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 List { | |
Cons(int, ~List), | |
Nil | |
} | |
impl List { | |
fn prepend(~self, x : int) -> ~List { | |
~Cons(x, self) | |
} | |
} |
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 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 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 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) | |
} | |
} | |
} |
OlderNewer