Skip to content

Instantly share code, notes, and snippets.

View rrichardson's full-sized avatar
💭
⚔️ Hacking Away

Rick Richardson rrichardson

💭
⚔️ Hacking Away
View GitHub Profile
pub struct Destructed<'a, T> {
fun: Box<for <'b> FnOnce<(&'b T,), ()> + 'a>,
active: bool,
val: T
}
impl<'a, T> Destructed<'a, T> {
pub fn new(val: T, f: Box<for <'b> FnOnce<(&'b T,), ()> + 'a>) -> Destructed<'a, T> {
Destructed { val: val, fun: f, active: true }
}
fn run<F> (endpoints: Vec<String>,
batch_size: uint,
query: String,
init_strings: Option<Vec<String>>,
f: F) -> Sender<Control<T>>
where F : Send + Fn(&Prepared, &T) -> Statement
{
let (tx1, rx1) : (Sender<Control<T>>, Receiver<Control<T>>) = channel();
spawn(|:| {
use std::ops::{Shl, Shr};
pub trait Subscriber<A> {
fn on_subscribe(&mut self, uint);
fn on_next(&mut self, t: A);
fn on_error(&mut self, err: &str);
fn on_complete(&mut self, force: bool);
}
pub trait Publisher<B> {
unsafe fn struct_to_bytes<T>(t: &T) -> &[u8] {
mem::transmute(raw::Slice::<u8> {
data: t as *const T as *const u8,
len: mem::size_of::<T>(),
})
}
stack backtrace:
1: 0x7f843f6c6850 - sys::backtrace::write::h5b05e7b061a35107Czt
2: 0x7f843f6e8a60 - failure::on_fail::h1e9b7e3de59488d1aPz
3: 0x7f843f6565e0 - rt::unwind::begin_unwind_inner::h23dcfb4c37870bd62tz
4: 0x7f843d7c3960 - rt::unwind::begin_unwind::h13789887957783664646
5: 0x7f843db5e580 - middle::ty::lookup_trait_def::h4590f6ca5c5cdfe2YK8
6: 0x7f843db7fcb0 - middle::ty::predicates_for_trait_ref::hb3e019a71a18e2d75L8
7: 0x7f843db57c30 - middle::traits::util::Elaborator<'cx, 'tcx>.Iterator::next::hbd30b487fd03287cfiU
8: 0x7f843db5cb60 - middle::traits::util::Supertraits<'cx, 'tcx>.Iterator::next::hcd7ed39c8850ea00QkU
9: 0x7f843eedac80 - astconv::ast_ty_to_ty::unboxed_closure.29245
@rrichardson
rrichardson / gist:27784b3771ff8044c1e2
Created January 10, 2015 21:54
ExpressJS boilerplate / starter
var express = require("express");
var expressSession = require("express-session");
var bodyParser = require("body-parser");
var http = require("http");
var path = require("path");
var passport = require("passport");
pub trait Subscriber {
type Input;
fn on_next(&mut self, t: Self::Input) -> bool;
fn on_subscribe(&mut self, usize) {
debug!("on_subscribe called");
}
fn on_error(&mut self, err: &str) {
error!("on_error called: {:?}", err);
}
Compiling rx v0.0.2 (file:///home/rick/Projects/RxRust)
src/reactor.rs:125:20: 125:41 error: the parameter type `T` may not live long enough
src/reactor.rs:125 proto: <T as Protocol>::new(),
^~~~~~~~~~~~~~~~~~~~~
src/reactor.rs:125:20: 125:41 help: consider adding an explicit lifetime bound `T: 'static`...
src/reactor.rs:125 proto: <T as Protocol>::new(),
^~~~~~~~~~~~~~~~~~~~~
src/reactor.rs:125:20: 125:41 note: ...so that the declared lifetime parameter bounds are satisfied
src/reactor.rs:125 proto: <T as Protocol>::new(),
^~~~~~~~~~~~~~~~~~~~~
pub struct DropCopyProto;
impl Protocol for DropCopyProto {
type Output = DropCopy;
fn new() -> DropCopyProto {
DropCopyProto
}
fn append(&mut self, buf: &AROIobuf) -> Option<(<Self as Protocol>::Output, AROIobuf, u32)> {
#[inline]
fn struct_to_bytes<T>(t: &T) -> &[u8] { unsafe {
mem::transmute(raw::Slice::<u8> {
data: t as *const T as *const u8,
len: mem::size_of::<T>(),
})
}}
#[inline]
fn bytes_to_struct<'a, T>(t: &'a [u8]) -> Option<&'a T> {