Skip to content

Instantly share code, notes, and snippets.

@dstu
dstu / playground.rs
Created April 24, 2018 23:24 — forked from rust-play/playground.rs
Code shared from the Rust Playground
use array::with;
mod array {
use std::marker::PhantomData;
use std::ops::{Deref, DerefMut};
#[derive(Clone,Copy)]
pub struct InvariantLifetime<'id>(
PhantomData<*mut &'id ()>);
@dstu
dstu / Cargo.toml
Created January 17, 2017 03:59
Unable to see the syn::Pat enum type
[package]
name = "syn_pat_compile"
version = "0.1.0"
authors = ["Stu Black <trurl@freeshell.org>"]
[dependencies]
syn = "0.10.6"
@dstu
dstu / playground.rs
Created December 17, 2015 01:45 — forked from anonymous/playground.rs
Shared via Rust Playground
#![feature(drain)]
use std::cmp::Ordering;
pub fn main() {
let mut x_vec = vec![1, 2, 3, 4];
let mut y_vec = vec![3, 4, 5];
// Slightly contrived example: iterate through two sorted sequences in
// tandem, merging them into a new sequence.
let mut xs = x_vec.drain(0..);
#![feature(append)]
use std::fmt;
use std::result::Result;
/// Simple tree data structure that owns its child nodes.
#[derive(Eq, PartialEq)]
struct Tree<T> {
data: T,
children: Vec<Tree<T>>,
@dstu
dstu / hashset.rs
Created January 16, 2015 07:26
Sticking a custom composite type into a HashSet.
use std::collections::HashSet;
#[deriving(Eq, Hash)]
struct Foo {
a: usize,
b: &'static str,
}
pub fn main() {
let mut s = HashSet::new();
@dstu
dstu / errordemo.scala
Created April 21, 2014 20:13
Dead code error in Scala macro definintion
package errordemo
import scala.annotation.StaticAnnotation
import scala.reflect.macros.whitebox.Context
class mymacro extends StaticAnnotation {
def macroTransform(annottees: Any*): Any = macro MacroImpl.macroImpl
}
class MacroImpl(val c: Context) {
@dstu
dstu / test.scala
Created April 3, 2014 04:56
Can't locate typeclass implementation during macro expansion
package mymacro.test
import scala.annotation.StaticAnnotation
import scala.language.experimental.macros
import scala.reflect.macros.Context
trait MyTypeClass[T] {
def something(c: Context): c.Tree
}
@dstu
dstu / test.scala
Created April 2, 2014 05:24
Failure to find type class implementation with Scala 2.10.4, Macro Paradise 2.0.0-M6
package mymacro.test
import scala.annotation.StaticAnnotation
import scala.language.experimental.macros
import scala.reflect.macros.Context
trait MyTypeClass[T] {
def something: Int
}
@dstu
dstu / Item.java
Last active August 29, 2015 13:57
Trying to get Scala to use a proper switch statement on a Java enum type
public enum Item {
ITEM1, ITEM2, ITEM3,
}
@dstu
dstu / gist:8838521
Last active August 29, 2015 13:56
scalac/sbt crash
$ sbt compile
Loading /usr/share/sbt/bin/sbt-launch-lib.bash
[info] Loading project definition from /home/stu/projects/scala-trees/project
[info] Set current project to PCFG parsing (in build file:/home/stu/projects/scala-trees/)
[info] Updating {file:/home/stu/projects/scala-trees/}scala-trees...
[info] Resolving org.scala-lang#scala-library;2.10.3 ...
[info] Resolving org.scalatest#scalatest_2.10;2.0 ...
[info] Resolving org.scala-lang#scala-reflect;2.10.0 ...
[info] Resolving org.scala-lang#scala-compiler;2.10.3 ...
[info] Resolving org.scala-lang#scala-reflect;2.10.3 ...