Skip to content

Instantly share code, notes, and snippets.

@SiegeLord
SiegeLord / test.rs
Created August 25, 2013 16:41
Ownership tricks
struct Resource(int);
struct Owner
{
target: ~Resource
}
impl Owner
{
fn set_target(&mut self, new_target: ~Resource)
@SiegeLord
SiegeLord / allegro_test.rs
Created August 25, 2013 23:56
Using Allegro from Rust
#[start]
fn start(argc: int, argv: **u8, crate_map: *u8) -> int
{
allegro::run(argc, argv, crate_map, main)
}
fn main()
{
let mut disp = allegro::Display::new(800, 600).unwrap();
let bmp = ~allegro::Bitmap::new(256, 256).unwrap();
@SiegeLord
SiegeLord / test.rs
Created August 27, 2013 20:33
Reference
mod foo
{
struct A;
}
mod bar
{
struct B
{
a: foo::A
@SiegeLord
SiegeLord / test.rs
Last active December 21, 2015 20:29
Flags
use extension::*;
macro_rules! flag_type
(
(mod $m:ident { $f: ident { $($n: ident = $v: expr),*} }) =>
{
pub mod $m
{
pub struct $f
{
@SiegeLord
SiegeLord / test.rs
Last active December 22, 2015 00:49
Arbitrary infix operators
fn main()
{
let a = NumType(7) /and/ (NumType(2) /and/ NumType(3));
println!("{}", *a);
}
struct NumType(int);
struct AndHelper
{
@SiegeLord
SiegeLord / commands
Last active December 22, 2015 10:09
Structural variant
rustc --lib test1.rs
warning: missing crate link meta `name`, using `test1` as default
warning: missing crate link meta `vers`, using `0.0` as default
rustc test2.rs -L.
test2.rs:16:10: 16:12 error: `C2` does not name a structure
test2.rs:16 let c2 = C2{a: 0};
^~
error: aborting due to previous error
@SiegeLord
SiegeLord / prop.rs
Created September 26, 2013 00:30
Properties
struct A
{
x: int
}
struct B<'self>
{
a: &'self mut A
}
@SiegeLord
SiegeLord / test.rs
Created September 28, 2013 01:39
Private modules
use A::B;
pub mod A
{
mod B
{
}
}
@SiegeLord
SiegeLord / priv.rs
Created September 28, 2013 02:17
Private implementation
use B::*;
pub struct S;
mod B
{
impl super::S
{
fn new()
{
super::S
@SiegeLord
SiegeLord / no_use.rs
Created September 28, 2013 03:52
It's no use...
pub struct S;
mod private
{
impl super::S
{
fn test(&self)
{
}
}