Skip to content

Instantly share code, notes, and snippets.

@14427
14427 / hkt.rs
Last active February 7, 2024 10:18
Higher-kinded type trait
use std::rc::Rc;
trait HKT<U> {
type C; // Current type
type T; // Type with C swapped with U
}
macro_rules! derive_hkt {
($t:ident) => {
impl<T, U> HKT<U> for $t<T> {
@14427
14427 / channelfail.rs
Last active December 12, 2015 01:08
Real channel fail
extern mod std;
use std::timer;
use std::uv;
fn sleep(ms: uint) {
let iotask = uv::global_loop::get();
timer::sleep(iotask, ms);
}
@14427
14427 / selecti_fail.rs
Last active December 11, 2015 18:49
This code fails an assertion
use pipes::*;
use task::spawn;
fn main() {
let (p1, c1) = pipes::stream();
let (p2, c2) = pipes::stream();
do spawn {
for int::range(1, 7) |i| {
c1.send(i);
@14427
14427 / signal_merge_test.rs
Created January 26, 2013 19:53
Signal merge test
use either::*;
use pipes::*;
use task::spawn;
pub trait Clone {
fn clone(&self) -> self;
}
impl<T: Copy> T: Clone {
fn clone(&self) -> T {
struct Noter {
note: &fn(),
drop {
if task::failing() {
(self.note)();
}
}
}
macro_rules! note (
@14427
14427 / gist:3924593
Created October 20, 2012 20:04
Rust ICE backtrace
rust: task failed at 'option::get none', /home/simon/Code/Rust/rust/src/rustc/rustc.rc:1
/usr/local/bin/../lib/librustrt.so(_ZN9rust_task13begin_failureEPKcS1_m+0x5d)[0x7efffa37afdd]
/usr/local/bin/../lib/librustrt.so(+0x3325d)[0x7efffa39325d]
/usr/local/bin/../lib/librustrt.so(upcall_fail+0x1d0)[0x7efffa37d930]
/usr/local/bin/../lib/librustc-c84825241471686d-0.5.so(+0x29807a)[0x7efffa85c07a]
/usr/local/bin/../lib/librustc-c84825241471686d-0.5.so(_ZN6middle2ty19fold_regions_and_ty16_f447a02294ab0ae3_05E+0x215)[0x7efffa859975]
/usr/local/bin/../lib/librustc-c84825241471686d-0.5.so(+0x297db6)[0x7efffa85bdb6]
/usr/local/bin/../lib/librustc-c84825241471686d-0.5.so(_ZN6middle2ty5subst17_ecd09f5a164ea9b23_05E+0x2fb)[0x7efffa75286b]
/usr/local/bin/../lib/librustc-c84825241471686d-0.5.so(_ZN6middle2ty17lookup_field_type17_a1fa3edba3eb94a23_05E+0x16e)[0x7efffa7a07be]
/usr/local/bin/../lib/librustc-c84825241471686d-0.5.so(+0x1dc62c)[0x7efffa7a062c]
@14427
14427 / gist:3834914
Created October 4, 2012 16:54
ICE backtrace
error: internal compiler error: unexpected failure
note: the compiler hit an unexpected failure path. this is a bug
note: try running with RUST_LOG=rustc=0,::rt::backtrace to get further details and report the results to github.com/mozilla/rust/issues
rust: task failed at 'explicit failure', /home/rustbuild/src/rustbot/workspace-snap-stage3-x86_64-unknown-linux-gnu/src/src/rustc/driver/rustc.rs:275
/home/simon/Code/Rust/incoming/rust/build/x86_64-unknown-linux-gnu/stage0/bin/../lib/librustrt.so(_ZN9rust_task13begin_failureEPKcS1_m+0x5d)[0x2b94b8b9fc5d]
/home/simon/Code/Rust/incoming/rust/build/x86_64-unknown-linux-gnu/stage0/bin/../lib/librustrt.so(+0x315ad)[0x2b94b8bb75ad]
/home/simon/Code/Rust/incoming/rust/build/x86_64-unknown-linux-gnu/stage0/bin/../lib/librustrt.so(upcall_fail+0x1d3)[0x2b94b8ba3373]
x86_64-unknown-linux-gnu/stage0/bin/rustc(_rust_main+0xb86)[0x411b56]
x86_64-unknown-linux-gnu/stage0/bin/rustc[0x411f84]
/home/simon/Code/Rust/incoming/rust/build/x86_64-unknown-linux-gnu/stage0/bin/../lib/l
@14427
14427 / gist:3808689
Created September 30, 2012 23:08
Sort performance
timsort
i 2**i *sort \sort /sort 3sort +sort %sort ~sort =sort !sort
10 1024 0.72 0.02 0.02 0.22 0.03 0.08 0.65 0.02 0.05
11 2048 1.47 0.03 0.03 0.05 0.04 0.13 1.14 0.03 0.07
12 4096 2.85 0.06 0.06 0.09 0.06 0.42 2.34 0.08 0.13
13 8192 9.06 0.11 0.09 0.12 0.10 1.05 6.81 0.09 0.26
14 16384 13.34 0.21 0.17 0.20 0.12 1.97 12.37 0.17 0.51
15 32768 29.73 0.40 0.31 0.39 0.41 7.54 21.64 0.13 0.98
16 65536 53.93 0.61 0.63 0.77 0.64 12.60 38.80 0.72 1.68
17 131072 104.48 1.66 1.27 2.22 1.27 28.74 81.28 0.70 3.64