Skip to content

Instantly share code, notes, and snippets.

@gavinb
gavinb / boring09.rs
Created February 18, 2014 04:29
Demonstrates a bug in c84890. Under OS X 10.9, crashes in receive code with null pointer.
// Rust IO Test
// Based on samples presented in Rob Pike's Go Concurrency talk
use std::libc::funcs::posix88::unistd::sleep;
use std::rand::random;
use std::comm::{Chan, Port};
struct Message {
string: ~str,
wait_chan: Chan<bool>,
@gavinb
gavinb / iter_stuff.rs
Last active December 20, 2015 16:19
Troubles with types, iterators and collections
fn main() {
// Match parsed group lengths with expected - test data
let group_lengths: ~[(&int, &int)] = ~[(&8, &8), (&4, &4), (&4, &4), (&4, &4), (&8, &12)];
// ~~~
// ~~~ Problem 1: all vs take_while and unpacking tuple
// ~~~
// This works
@gavinb
gavinb / repeat_iterator.rs
Last active December 19, 2015 23:28
Experimental repeat() iterator for Rust
// iterator.rs
pub trait IteratorUtil<A> {
// ...
fn repeat_(&mut self) -> RepeatIterator<A, Self>;
}
//...
#[inline]
fn repeat_(&mut self) -> RepeatIterator<A, T> {
RepeatIterator{iter: self, iter_orig: copy self}
@gavinb
gavinb / tcptest.rs
Created July 14, 2013 22:54
Rust Networking test code which triggers an odd linker error relating to `rt::sched::__extensions__`.
// Cribbed from Rust libstd test code
// Causes a linker error on OS X
use std::cell::Cell;
use std::task::Task;
use std::rt::io::net::tcp;
use std::rt::io::net::ip;
use std::rt::local::Local;
use std::rt::io::{Reader, Writer, Listener};
@gavinb
gavinb / clutils.c
Created June 7, 2013 12:26
Convert an OpenCL cl_error code into a string.
/*
OpenCL Utility functions
*/
#ifndef CLUTILS_H_INC
#define CLUTILS_H_INC
#include <OpenCL/cl.h>
const char* clErrorString(cl_int err);