Skip to content

Instantly share code, notes, and snippets.

@DaGenix
DaGenix / gist:5545095
Last active December 17, 2015 03:39
Rust code that won't compile
// This code works fine
fn get(f: ~fn() -> int) -> ~fn() -> int {
|| {
f()
}
}
fn main() {
get(|| {8})();
}
@DaGenix
DaGenix / gist:5793174
Created June 16, 2013 19:49
Short (possibly invalid) program that makes the rust compiler crash with an assertion
trait Printable {
fn print(&self);
}
fn test(o: &[~Printable]) {
for o.each |&p| {
p.print();
}
}
struct Works {
val: int
}
impl Works {
fn fn1(&mut self) {
// This seems to work perfectly fine
self.fn2(&const self.val);
}
fn fn2(&mut self, x: &const int) {
@DaGenix
DaGenix / gist:5895932
Created June 30, 2013 16:53
Seemingly incorrect use of uninitialized variable error
fn test() -> (u32, u32) {
return (0, 0,);
}
fn main() {
let mut X0: u32;
let mut X1: u32;
(X0, X1) = test();
}
fn test() -> (u32, u32) {
return (0, 0,);
}
fn main() {
let mut X0 = 0u32;
let mut X1 = 0u32;
(X0, X1) = test();
}
@DaGenix
DaGenix / gist:5898568
Created July 1, 2013 05:35
call twice thing
fn call(f: &fn()) {
f();
}
fn call_twice(f: &fn()) {
call(f);
call(f);
}
fn main() {
@DaGenix
DaGenix / gist:6288591
Created August 20, 2013 23:19
This doesn't work for me
use std::unstable::simd::u32x4;
static test: u32x4 = u32x4(0, 0, 0, 0);
fn main() {
}
/*!
this module implements the AES algorithm completely in software without using any table lookups or
other timing dependant mechanisms. This module actually contains two seperate implementations - an
implementation that works on a single block at a time and a second implementation that processes 8
blocks in parallel. Some block encryption modes really only work if you are processing a single
blocks (CFB, OFB, and CBC encryption for example) while other modes are trivially parallelizable
(CTR and CBC decryption). Processing more blocks at once allows for greater efficiency, especially
when using wide registers, such as the XMM registers available in x86 processors.
struct Struct<'self, B> {
val: B
}
impl <'self, B: MutableVector<'self, u8>> Struct<'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 };