Skip to content

Instantly share code, notes, and snippets.

View bbatha's full-sized avatar
🏠
Working from home

Ben Batha bbatha

🏠
Working from home
View GitHub Profile
use std::collections::HashSet;
use std::hash::Hash;
pub struct Dag<'a, L: 'a, N: 'a> {
leaves: HashSet<L>,
// Might be better as an arena but that isn't available the playpen
nodes: Vec<Node<'a, L, N>>
}
impl<'a, L: 'a + Eq + Hash, N: 'a> Dag<'a, L, N> {
@bbatha
bbatha / gist:989d84c6e4aeca637e99
Created June 15, 2015 20:20
DAG implementation
use std::collections::HashSet;
use std::hash::Hash;
use typed_arena::Arena;
#[derive(Clone)]
pub enum Edges<'a, L: 'a, N: 'a + Hash> {
Leaves(Vec<&'a L>),
Children(Vec<&'a Node<'a, L, N>>)
}
@bbatha
bbatha / gist:8a1030c2d0f78be9eab1
Created April 18, 2015 19:44
Life time error
[bbatha@dev threadpool-rs]% cargo test
Compiling threadpool v0.0.1 (file:///home/bbatha/projects/threadpool-rs)
src/lib.rs:42:12: 42:16 error: `pool` does not live long enough
src/lib.rs:42 pool.execute(move || {
^~~~
src/lib.rs:38:19: 47:6 note: reference must be valid for the block at 38:18...
src/lib.rs:38 fn it_works() {
src/lib.rs:39 let mut pool = ScopedThreadPool::new(2);
src/lib.rs:40
src/lib.rs:41 for _ in (0..3) {
@bbatha
bbatha / gist:9df1fcc1fa0a72a9f57d
Created April 13, 2015 18:05
Arc::new() lifetime error
fn it_works() {
let guards: Vec<thread::JoinGuard<()>> = Vec::with_capacity(3);
{
let mut pool = ScopedThreadPool::new(2);
for _ in (0..3) {
guards.push(pool.execute(move || {
thread::sleep_ms(1000);
println!("Things are happening!");
}));