Skip to content

Instantly share code, notes, and snippets.

@dylanede
dylanede / playground.rs
Last active August 25, 2017 15:20 — forked from anonymous/playground.rs
Rust code shared from the playground
// Need an endpoint to drive everything (provide top level criteria) - Nodes don't actually have the data going through them - only construct and modify callbacks
// Need an abstraction for a dynamically updating time serise - notification of points adding, updating and removing, refreshing - NOT a stream, kind of like a signal for multiple values in parallel
// Node - given criteria object, constructs a collection of output points, delegating where necessary
// criteria object may be modified at runtime - node should then modify the subscription
// Should be possible to have node sub-graph templates (maybe just functions) for generation based on changes in data source sets
// Internally to the graph, criteria may be dynamically updated at run time (e.g. to implement "join-on")
// Criteria:
@dylanede
dylanede / playground.rs
Created April 26, 2016 13:00 — forked from anonymous/playground.rs
Static string hash map optimisations
use std::cell::RefCell;
use std::collections::HashMap;
use std::hash::{ Hash, SipHasher, Hasher };
thread_local!(static SYMBOL_HASHES: RefCell<HashMap<(*const u8, usize), u64>> = RefCell::new(HashMap::new()));
struct StaticSymbol {
string: &'static str,
hash: u64,
}
@dylanede
dylanede / list merge.rs
Created February 19, 2016 17:29 — forked from anonymous/playground.rs
Shared via Rust Playground
trait Merge<A, B> {
type Out;
fn merge(a: A, b: B) -> Self::Out;
}
type MergeOut<A, B> = <() as Merge<A, B>>::Out;
fn merge<A, B>(a: A, b: B) -> MergeOut<A, B> where (): Merge<A, B> {
<() as Merge<A, B>>::merge(a, b)
}
struct Unknown;
macro_rules! derive_merge_unknown {
@dylanede
dylanede / widget.rs
Created January 7, 2016 23:22 — forked from anonymous/playground.rs
Shared via Rust Playground
use std::any::Any;
use std::rc::Rc;
trait AsAny {
fn as_any(&self) -> &Any;
}
impl<T: Any> AsAny for T {
fn as_any(&self) -> &Any { self }
}
@dylanede
dylanede / playground.rs
Created January 5, 2016 21:50 — forked from anonymous/playground.rs
Shared via Rust Playground
use std::collections::HashMap;
use std::marker::PhantomData;
use std::collections::hash_map;
pub trait DiffableIters<'a, T: Diffable> where T::Key: 'a, T::ListChild: 'a {
type KeyIter: Iterator<Item=&'a T::Key>;
type ListChildIter: Iterator<Item=&'a T::ListChild>;
}
pub type KeyIter<'a, T> = <T as DiffableIters<'a, T>>::KeyIter;
@dylanede
dylanede / playground.rs
Created October 18, 2015 21:20 — forked from anonymous/playground.rs
Shared via Rust Playground
#![feature(optin_builtin_traits)]
use std::marker::PhantomData;
trait Lookup<K> {
type V;
fn get(&self) -> &Self::V;
}
struct Nil;
@dylanede
dylanede / playground.rs
Created October 18, 2015 21:08 — forked from anonymous/playground.rs
Shared via Rust Playground
#![feature(optin_builtin_traits)]
use std::marker::PhantomData;
trait Lookup<K> {
type V;
fn get(&self) -> &Self::V;
}
struct Nil;
@dylanede
dylanede / playground.rs
Created October 17, 2015 16:54 — forked from anonymous/playground.rs
Shared via Rust Playground
#![feature(optin_builtin_traits)]
use std::marker::PhantomData;
struct Nil;
struct Cons<H, T>(H, T);
struct Pair<A, B>(A, B);
trait Lookup_<S, Env> { type Type; }
type Lookup<S, Env> = <() as Lookup_<S, Env>>::Type;
@dylanede
dylanede / playground.rs
Created October 17, 2015 13:45 — forked from anonymous/playground.rs
Shared via Rust Playground
#![feature(optin_builtin_traits)]
use std::marker::PhantomData;
struct Nil;
struct Cons<H, T>(H, T);
struct Pair<A, B>(A, B);
trait Lookup_<S, Env> { type Type; }
type Lookup<S, Env> = <() as Lookup_<S, Env>>::Type;
@dylanede
dylanede / playground.rs
Created October 16, 2015 13:00 — forked from anonymous/playground.rs
Shared via Rust Playground
#![feature(optin_builtin_traits)]
use std::marker::PhantomData;
struct Nil;
struct Cons<H, T>(H, T);
struct Zero;
struct One;
trait UInt {