Skip to content

Instantly share code, notes, and snippets.

@Thiez
Thiez / gist:5438985
Last active December 16, 2015 12:59
struct Car {
color: ~str,
miles: int,
}
impl Car {
fn new() -> ~Car { ~Car{color: ~"none", miles: 0,} }
}
macro_rules! simple_eq(( $ T : ident -> $ l : ident , $ r : expr ) =>
(
{ let temp = $ T :: new ( ) ; & temp . $ l == & temp .
@Thiez
Thiez / RegionBug
Created May 16, 2013 19:24
Copy of a test from libcore/iterator.rs that somehow can't compile.
use core::iterator::UnfoldrIterator;
fn test_unfoldr() {
fn count(st: &mut uint) -> Option<uint> {
if *st < 10 {
let ret = Some(*st);
*st += 1;
ret
} else {
None
@Thiez
Thiez / gist:5850798
Created June 24, 2013 15:15
Cute 'findBest' with iter and fold and without evil copies.
use std::num::*;
// Given a collection and a score function, find the item with highest score.
fn findBest<'t,T,C:Ord>(src:&'t [T], scoreFunc:&fn(x:&'t T)->C)->Option<(&'t T,uint,C)> {
let mut it = src.iter();
let mut i = 0;
match it.next() {
None => None,
Some(first) => {
let firstScore = scoreFunc(first);
@Thiez
Thiez / gist:df2072140f5483ff9105
Created June 17, 2014 23:22
Peano Matrix Madness
#![feature(asm, globs, macro_rules, phase, simd, struct_variant, quad_precision_float)]
extern crate collections;
extern crate native;
use std::num::{zero,Zero};
#[deriving(PartialEq,Eq)]
struct PeanoOne;
#[deriving(PartialEq,Eq)]
use std::io::timer;
use std::time::Duration;
use std::sync::Future;
trait Constraint {
fn is_satisfied(&self) -> bool;
}
#[deriving(Send)]
struct Foo {
name: &'static str,
@Thiez
Thiez / gist:1adac91aff54c997f355
Last active August 29, 2015 14:16 — forked from anonymous/gist:a9c9c1c028d69e3b7219
It just keeps getting better. Now with box patterns.
#![feature(box_patterns)]
pub enum Expression {
Identifier(String),
Function(String, Box<Expression>),
Application(Box<Expression>, Box<Expression>),
}
impl Expression {
fn is_variable_free(&self, var: &str) -> bool {
@Thiez
Thiez / playground.rs
Last active July 7, 2016 09:00 — forked from anonymous/playground.rs
Shared via Rust Playground
use std::collections::HashMap;
fn main() {
let port = "1025";
// Works if I reverse these two lines
let mut data = HashMap::new();
let port = port.to_string();
data.insert("port", &port);
//replacement constant
pub const P: [u8; 256] = [
60, 63, 58, 160, 99, 193, 14, 189, 7, 116, 255, 230, 172,
201, 132, 186, 10, 203, 211, 20, 180, 106, 0, 21, 174, 119,
39, 225, 238, 38, 208, 76, 223, 216, 213, 150, 118, 77, 82,
42, 125, 68, 34, 232, 107, 252, 195, 247, 243, 169, 248, 120,
254, 123, 171, 103, 146, 65, 98, 61, 147, 114, 67, 134, 251,
59, 234, 87, 88, 53, 40, 196, 79, 168, 95, 113, 104, 83,
36, 73, 57, 190, 249, 75, 242, 129, 143, 110, 237, 94, 145,
97, 179, 197, 206, 24, 1, 16, 128, 89, 45, 101, 71, 192,
@Thiez
Thiez / main.rs
Created October 26, 2017 10:40 — forked from steveklabnik/main.rs
The Results of the Expressive C++17 Coding Challenge in Rust
use std::io::{Read, Write};
use std::fs::File;
fn main() {
let args = ::std::env::args().collect::<Vec<_>>();
// skip the program name
if args.len() != 5 {
println!("Usage: {} <filename> <columnname> <replacement> <output_filename>", args[0]);
}
@Thiez
Thiez / playground.rs
Created June 3, 2018 21:57 — forked from rust-play/playground.rs
Code shared from the Rust Playground
fn main() {}
fn unwrap_array<T>(input: [Option<T>; 2]) -> Option<[T; 2]> {
// Note: `{ }` is required here.
match {input} {
[Some(a), Some(b)] => Some([a, b]),
_ => None,
}
}