Skip to content

Instantly share code, notes, and snippets.

@ben0x539
ben0x539 / foo.rs
Last active December 14, 2015 07:29
struct Vec<'self, T> {
vec: &'self [T]
}
fn advance<'lt, T>(w: &mut Vec<'lt, T>) {
w.vec = vec::slice(w.vec, 1, w.vec.len());
}
fn wrap<'lt, T>(v: &'lt [T]) -> Vec<'lt, T> {
Vec { vec: v }
struct S<'self> {
v: &int
}
fn f<'lt>(_s: &S<'lt>) {}
fn main() {
f(& S { v: &42 });
}
# zero ruby IO happens here:
def assert_type(x, klass)
return if x.kind_of?(klass)
raise TypeError, "expected #{klass}, got #{x.inspect} :: #{x.class}"
end
class IOAction < Struct.new(:primop, :args)
end
@ben0x539
ben0x539 / baz.rs
Last active December 17, 2015 02:59
use core::unstable::intrinsics;
struct S;
impl Drop for S {
fn finalize(&self) {}
}
fn discard(_s: S) {}
fn main() {
unsafe {
use core::util::replace;
#[deriving(Clone)]
struct S(int);
impl Drop for S {
fn finalize(&self) {
io::println(fmt!("~S(%?)", **self));
}
}
trait Allocator {
unsafe fn store<T>(obj: T) -> *T;
unsafe fn store_mut<T>(obj: T) -> *mut T;
unsafe fn release<T>(ptr: *T);
}
struct Malloc;
struct OwnedPtr;
impl Allocator for Malloc {
#![feature(macro_rules)]
use std::task;
use std::any::{Any, AnyRefExt};
use std::io;
use std::iter;
// a channel for transmitting failure context info while unwinding
local_data_key!(diag_tx_key: Sender<FailureContext>)
use self::string10_mod::inlinevec::InlineVec as VecString10;
use self::int4_mod::inlinevec::InlineVec as FourBoundedArray;
mod string10_mod {
type T = String;
static N: uint = 10;
static Size: uint = 3 * 8;
static Align: uint = 8;
#[path = "../inlinevec.rs"] pub mod inlinevec;
}
fn with_current_dir<F, T>(path: &Path, f: F) -> std::io::Result<T>
where F: FnOnce() -> T {
let previous_dir = try!(current_dir());
let rewind = || {
match set_current_dir(&previous_dir) {
Err(e) => {
let _ = set_current_dir("/");
let _ = writeln!(
&mut stderr(),
"couldn't chdir back to {:?}: {:?}",
extern crate gif;
fn make_file() {
// http://www.piston.rs/image/gif/index.html#encoding-gif-files
use gif::{Frame, Encoder, Repeat, SetParameter};
use std::fs::File;
use std::borrow::Cow;
let color_map = &[0xFF, 0xFF, 0xFF, 0, 0, 0];
let (width, height) = (6, 6);