Skip to content

Instantly share code, notes, and snippets.

@anka-213
anka-213 / prime_list.rs
Last active April 19, 2016 21:15 — forked from anonymous/playground.rs
Shared via Rust Playground
#![allow(dead_code, unused_variables)]
struct PrimeList {
primes: Vec<i32>,
}
/// Basically the same as
/// self.primes.iter().cloned().chain(self) on a PrimeList
struct PrimeIter<'a> {
primes: &'a mut PrimeList,
@anka-213
anka-213 / doNotation.rs
Last active April 13, 2016 13:26 — forked from anonymous/playground.rs
Shared via Rust Playground
#![feature(trace_macros)]
#![feature(log_syntax)]
//trace_macros!(true);
macro_rules! id {($e : expr) => ($e)}
macro_rules! vecc {($($t:tt)*) => (Vecc{v:vec!($($t)*)})}
macro_rules! mdo {
@anka-213
anka-213 / LinkedList.rs
Last active April 13, 2016 13:07 — forked from anonymous/playground.rs
Using enum
use std::iter::FromIterator;
enum List { Nil, Cons{value: i32, next: Box<List>}}
fn main() {
let v = vec![1, 5, 3, 8, 12, 56, 1230, 2, 1];
//let root: List = v.iter().cloned().collect();
let root = List::from_iter(v);
@anka-213
anka-213 / playground.rs
Created April 13, 2016 14:48 — forked from anonymous/playground.rs
Shared via Rust Playground
use std::borrow::Cow;
use std::sync::Arc;
fn fizz_buzz(i: i32) -> Cow<'static, str> {
if i % 15 == 0 {
"FizzBuzz".into()
} else if i % 5 == 0 {
"Buzz".into()
} else if i % 3 == 0 {
"Fizz".into()
@anka-213
anka-213 / playground.rs
Created April 13, 2016 14:48 — forked from anonymous/playground.rs
Shared via Rust Playground
fn main() {
use std::borrow::Cow;
#[allow(dead_code)]
fn abs_all(input: &mut Cow<[i32]>) {
for i in 0..input.len() {
let v = input[i];
if v < 0 {
// clones into a vector the first time (if not already owned)
input.to_mut()[i] = -v;
@anka-213
anka-213 / playground.rs
Created April 13, 2016 15:32 — forked from anonymous/playground.rs
Shared via Rust Playground
#![feature(trace_macros)]
#![feature(log_syntax)]
//trace_macros!(true);
macro_rules! id {($e : expr) => ($e)}
macro_rules! vecc {($($t:tt)*) => (Vecc{v:vec!($($t)*)})}
macro_rules! mdo {
@anka-213
anka-213 / playground.rs
Created April 14, 2016 14:20 — forked from anonymous/playground.rs
Shared via Rust Playground
use std::mem::{replace};
#[derive(Clone, Debug)]
struct HasDrop(i32);
impl Drop for HasDrop {
fn drop(&mut self) {
println!("Dropping {}!", self.0);
}
}
@anka-213
anka-213 / playground.rs
Created April 14, 2016 17:04 — forked from anonymous/playground.rs
Shared via Rust Playground
#![feature(trace_macros)]
trace_macros!(true);
/// Piano numbers
#[derive(Debug)]
struct S<T>(T);
trait ToInt {fn to_int(self) -> i32;}
impl ToInt for i32 {fn to_int(self) -> i32 {self}}
@anka-213
anka-213 / playground.rs
Created April 14, 2016 17:04 — forked from anonymous/playground.rs
Shared via Rust Playground
#![feature(trace_macros)]
trace_macros!(true);
macro_rules! wrap {
($n:expr) => (wrap!(S($n)))
}
macro_rules! wrap_nocrash {
($($n:tt)*) => (wrap_nocrash!(S($($n)*)))
}
@anka-213
anka-213 / playground.rs
Created April 14, 2016 18:11 — forked from anonymous/playground.rs
Shared via Rust Playground
#![feature(trace_macros)]
trace_macros!(true);
macro_rules! wrap {
($n:expr) => (wrap!(S($n)))
}
macro_rules! wrap_nocrash {
($($n:tt)*) => (wrap_nocrash!(S($($n)*)))
}