Skip to content

Instantly share code, notes, and snippets.

@DaGenix
DaGenix / gist:43f106718de53712ad75
Created January 18, 2015 03:11
assoc type ice
se std::ops::Deref;
pub trait Data: Deref<Target = Self::Item> {
type Item;
}
fn main() {
}
@DaGenix
DaGenix / foo9.rs
Created February 10, 2014 02:04
this should compile, right?
pub trait Even {
fn say(&self);
}
impl <'a, E: Even> Even for &'a mut E {
fn say(&self) { }
}
pub trait Odd {
fn say(&self);
pub struct ReaderRef<'a, R> {
priv reader: &'a mut R
}
impl <'a, R: Reader> ReaderRef<'a, R> {
pub fn new<'a>(reader: &'a mut R) -> ReaderRef<'a, R> {
ReaderRef {
reader: reader
}
}
@DaGenix
DaGenix / foo.rs
Last active August 29, 2015 13:55
Question about generic impls
trait SomeTrait { }
struct SomeStruct;
impl SomeTrait for SomeStruct { }
fn foo<T: SomeTrait>(_: T) { }
fn main() {
// This works fine
@DaGenix
DaGenix / gist:8381853
Last active January 3, 2016 00:19
Conflicting implementation bug (I think)
trait T1 { }
trait T2 { }
struct S1;
impl T1 for S1 { }
impl <S: T2> T1 for S { }
@DaGenix
DaGenix / gist:7695515
Created November 28, 2013 17:29
complete output of make check-stage1-rustpkg
make check-stage1-rustpkg
cfg: build triple x86_64-unknown-linux-gnu
cfg: host triples x86_64-unknown-linux-gnu
cfg: target triples x86_64-unknown-linux-gnu
cfg: enabling more debugging (CFG_ENABLE_DEBUG)
cfg: host for x86_64-unknown-linux-gnu is x86_64
cfg: os for x86_64-unknown-linux-gnu is unknown-linux-gnu
cfg: using gcc
cfg: no pandoc found, omitting docs
cfg: no node found, omitting docs
@DaGenix
DaGenix / testmp.rs
Last active December 28, 2015 20:09
/*
Here is my goal: I'd like to have a struct that basically operates as a state
machine. I'd like the current state to be represented as an enum which contains
a non-copyable value inside it related to the current state. When proessing each
state, I'd like to deconstruct the state, pull out the value inside it, and then
put a new value into a new state and transition to that state. In the code
I'm actually working on, I'm not allocating on the heap on state transitions,
but I think this is more readable for this question. Anyway, is there a better
way to do that than by using this next_state() function that I've cooked up?
My first attempt was to directly match on the state value, but, I got errors
@DaGenix
DaGenix / gist:7508248
Created November 17, 2013 02:17
Lifetime thing
trait GetBuffer<'self> {
fn get(&self) -> &'self [u8];
}
// This works
struct Buff1<'self> {
b: &'self [u8]
}
impl <'self> GetBuffer<'self> for Buff1<'self> {
fn get(&self) -> &'self [u8] { self.b }
@DaGenix
DaGenix / gist:7390603
Last active December 27, 2015 21:19
type_id collision
use std::hash;
use std::hash::Streaming;
// I believe that this pretty much the same thing as hash_crate_independent() in ty.rs
// for a ty_struct on a 64-bit platform
fn hash_struct(local_hash: &str, node: u64) -> u64 {
let mut state = hash::default_state();
state.input([18]);
state.input(local_hash.as_bytes());
do node.iter_bytes(true) |bytes| { state.input(bytes); true };
struct Struct<'self, B> {
val: B
}
impl <'self, B: MutableVector<'self, u8>> Struct<'self, B> {
}