Skip to content

Instantly share code, notes, and snippets.

struct S;
trait A
{
fn test(self);
}
impl<'l> A for &'l S
{
fn test(self)
@SiegeLord
SiegeLord / components.rs
Last active August 29, 2015 13:56
Component test
struct Location
{
x: f32,
y: f32
}
struct Velocity
{
vx: f32,
vy: f32
@SiegeLord
SiegeLord / test.rs
Created February 19, 2014 19:50
Hehehe
trait MyMul<RHS, Res>
{
fn mul(&self, rhs: &RHS) -> Res;
}
impl<T: ToPrimitive> MyMul<f64, f64> for T
{
fn mul(&self, rhs: &f64) -> f64
{
self.to_f64().unwrap() * *rhs
@SiegeLord
SiegeLord / errors
Created February 7, 2014 17:54
Trait bug
test.rs:24:3: 24:19 error: multiple applicable methods in scope
test.rs:24 self.get().sin()
^~~~~~~~~~~~~~~~
test.rs:22:2: 25:3 note: candidate #1 is `Sin$T::sin`
test.rs:22 fn sin(&self) -> f32
test.rs:23 {
test.rs:24 self.get().sin()
test.rs:25 }
test.rs:24:3: 24:19 note: candidate #2 is `std::f32::Real$f32::sin`
test.rs:24 self.get().sin()
@SiegeLord
SiegeLord / test.rs
Created February 6, 2014 17:56
Chaining results
#[feature(macro_rules)];
struct Obj;
impl Doer<Obj> for Obj
{
fn func1<'l>(&'l self) -> Result<&'l Obj, ~str>
{
Ok(self)
}
RustAlgebloat/src/vector/maps.rs:22:3: 23:3 error: multiple applicable methods in scope
RustAlgebloat/src/vector/maps.rs:22 a.sin()
RustAlgebloat/src/vector/maps.rs:23 }
RustAlgebloat/src/vector/maps.rs:35:2: 38:3 note: candidate #1 is `vector::maps::VectorSinOp$T::sin`
RustAlgebloat/src/vector/maps.rs:35 fn sin(&self) -> VectorUnOp<T, SinOp>
RustAlgebloat/src/vector/maps.rs:36 {
RustAlgebloat/src/vector/maps.rs:37 VectorUnOp::new(self.clone(), SinOp::new())
RustAlgebloat/src/vector/maps.rs:38 }
RustAlgebloat/src/vector/maps.rs:22:3: 23:3 note: candidate #2 is `std::f32::Real$f32::sin`
RustAlgebloat/src/vector/maps.rs:22 a.sin()
extern mod extra;
use std::ops::Add;
use std::vec;
use std::fmt;
use std::io::Writer;
use std::num::min;
trait VectorGet
{
@SiegeLord
SiegeLord / test.rs
Last active December 30, 2015 10:49
Label setting
use std::io;
fn test1(adder: |add: |x: int, lw: |&mut io::Writer|||)
{
let mut out = io::stdout();
let w = &mut out as &mut io::Writer;
let add = |x: int, lw: |&mut io::Writer||
{
writeln!(w, "Location: {}", x);
@SiegeLord
SiegeLord / test.rs
Created November 2, 2013 22:27
NoSuck<E>
use std::num::Zero;
trait VectorOf<E>
{
fn new() -> Self;
fn get<'l>(&'l self, i: uint) -> &'l E;
}
impl<E> VectorOf<E> for ~[E]
{
@SiegeLord
SiegeLord / commands
Created October 31, 2013 03:09
LDC bug
ldc2 -relocation-model=pic -c test1.d
ldc2 -relocation-model=pic -c test2.d
ldc2 -shared -of test.so test1.o test2.o