Skip to content

Instantly share code, notes, and snippets.

@anka-213
anka-213 / gc.rs
Last active May 12, 2016 22:44 — forked from anonymous/playground.rs
Shared via Rust Playground
#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(unused_mut)]
struct Asdf(i32, Option<Gc<Asdf>>);
struct Gc<T>(*const T);
impl<T> Drop for Gc<T> {
fn drop(&mut self) {
@anka-213
anka-213 / mbox.rs
Last active May 12, 2016 22:37 — forked from anonymous/playground.rs
Shared via Rust Playground
// #![allow(dead_code)]
// #![allow(unused_variables)]
// #![allow(unused_mut)]
#![feature(question_mark)]
use std::sync::Mutex;
use std::sync::Arc;
use std::collections::VecDeque;
use std::thread;
use std::ops::Deref;
@anka-213
anka-213 / linked_list.rs
Last active April 19, 2016 21:14 — forked from anonymous/playground.rs
Shared via Rust Playground
//#![allow(dead_code)]
use std::iter::FromIterator;
// Example of linked lists -- Comes from stackoverflow
enum List { Nil, Cons{value: i32, next: Box<List>}}
fn main() {
let v = vec![1, 5, 3, 8, 12, 56, 1230, 2, 1];
@anka-213
anka-213 / Primes.rs
Created April 19, 2016 21:07 — forked from anonymous/playground.rs
Shared via Rust Playground
#![allow(dead_code, unused_variables)]
struct PrimeList {
primes: Vec<i64>,
}
/// Basically the same as
/// self.primes.iter().cloned().chain(self) on a PrimeList
struct PrimeIter<'a> {
primes: &'a mut PrimeList,
@anka-213
anka-213 / playground.rs
Created April 19, 2016 21:00 — forked from anonymous/playground.rs
Shared via Rust Playground
#[derive(Debug)]
struct Parent {
count: u8,
}
#[derive(Debug)]
struct Child<'a> {
parent: &'a Parent,
}
@anka-213
anka-213 / peano.rs
Last active April 19, 2016 21:00 — forked from anonymous/playground.rs
Shared via Rust Playground
#![feature(trace_macros)]
trace_macros!(true);
/// Piano numbers
#[derive(Debug, Clone, Copy)]
struct S<T>(T);
trait ToInt {
fn to_int(self) -> i32;
}
@anka-213
anka-213 / euler36.rs
Created April 15, 2016 18:54 — forked from anonymous/playground.rs
Project Euler Problem 36: Double-base palindromes
// Project Euler Problem 36: Double-base palindromes
fn binary(n: i32) -> String {
format!("{:b}", n)
}
fn decimal(n: i32) -> String {
n.to_string()
}
fn is_palindrome(s: String) -> bool {
@anka-213
anka-213 / playground.rs
Created April 15, 2016 00:30 — forked from anonymous/playground.rs
Shared via Rust Playground
use std::sync::Once;
pub struct Lazy<T: Sync>(pub *const T, pub Once);
impl<T: Sync> Lazy<T> {
#[inline(always)]
pub fn get<F>(&'static mut self, f: F) -> &T
where F: FnOnce() -> T
{
unsafe {
@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)*)))
}
@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)*)))
}