Skip to content

Instantly share code, notes, and snippets.

@JeffBelgum
JeffBelgum / list_push_fn
Last active December 25, 2015 17:49
Linked List push function
#[deriving(ToStr, Clone, Eq)]
enum List<T> {
Cons(T, @mut List<T>),
Nil
}
/*
* from brson: it could be more efficient by avoiding that clone,
* since the cost of cloning a T could be arbitrary.
*
#[deriving(Clone, Eq)]
struct Node<T> {
v: T,
next: @mut Option<Node<T>>
}
#[deriving(Clone, Eq)]
struct List<T> {
priv head: @mut Option<Node<T>>
}
@JeffBelgum
JeffBelgum / list_comprehensions.rs
Created September 26, 2014 00:03
Python list comprehensions in Rust
#![feature(macro_rules)]
/// MIT license etc. etc.
///
/// Experimenting with Python-like list comprehensions.
///
/// An attempt to explore the possibility space for ergonomic improvements
/// in Rust that can come post v1.0. Notice that there are not type declerations.
/// Aside from the "c!" macro invocation, Rust allows for an exact copy of the
/// Python comprehension syntax.