This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::mem::{replace}; | |
#[derive(Clone, Debug)] | |
struct HasDrop(i32); | |
impl Drop for HasDrop { | |
fn drop(&mut self) { | |
println!("Dropping {}!", self.0); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![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}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(trace_macros)] | |
trace_macros!(true); | |
macro_rules! wrap { | |
($n:expr) => (wrap!(S($n))) | |
} | |
macro_rules! wrap_nocrash { | |
($($n:tt)*) => (wrap_nocrash!(S($($n)*))) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(trace_macros)] | |
trace_macros!(true); | |
macro_rules! wrap { | |
($n:expr) => (wrap!(S($n))) | |
} | |
macro_rules! wrap_nocrash { | |
($($n:tt)*) => (wrap_nocrash!(S($($n)*))) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(trace_macros)] | |
trace_macros!(true); | |
/// Piano numbers | |
#[derive(Debug, Clone, Copy)] | |
struct S<T>(T); | |
trait ToInt { | |
fn to_int(self) -> i32; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[derive(Debug)] | |
struct Parent { | |
count: u8, | |
} | |
#[derive(Debug)] | |
struct Child<'a> { | |
parent: &'a Parent, | |
} |