Skip to content

Instantly share code, notes, and snippets.

View pzol's full-sized avatar

Piotr Zolnierek pzol

View GitHub Profile
#[deriving(Show, Clone, PartialEq)]
struct City<'a> {
name: &'a str,
country: &'a str
}
impl<'a> City<'a> {
fn prototype() -> City<'a> {
City { name: "", country: "" }
@pzol
pzol / result.rs
Last active August 29, 2015 14:07
struct FooResult {
good: Option<String>,
bad: Option<String>
}
impl FooResult {
fn new(result: Result<String, String>) -> FooResult {
match result {
enum Foo {
Bar(uint),
Baz(i32)
}
fn dest(Bar(u): Foo) {
}
extern crate serialize;
use std::collections::TreeMap;
use serialize::json::ToJson;
use serialize::json;
use super::case_folds::CaseFolds;
use super::{ Category, HotelsRequest };
#[deriving(Show)]
@pzol
pzol / list.rs
Last active August 29, 2015 14:06
#[deriving(PartialEq, Show, Clone)]
enum List<T> {
Cons(T, Box<List<T>>),
Nil
}
impl<'a, T:Clone> List<T> {
fn empty() -> List<T> {
Nil
@pzol
pzol / linked_list.rb
Created September 1, 2014 11:06
Linked List in ruby
require 'deterministic/enum'
List = Deterministic::enum {
Cons(:head, :tail)
Nil()
}
Deterministic::impl(List) {
class EmptyListError < StandardError; end
stack backtrace:
1: 0x10e472c45 - rt::backtrace::imp::write::hd2f888e449bbd94eoiq
2: 0x10e475dc3 - failure::on_fail::he27adfa3d8f252c2Tyq
3: 0x10e47ceb5 - unwind::begin_unwind_inner::h5b97974f8716d208S5d
4: 0x10e47ca8b - unwind::begin_unwind_fmt::hc263c2d677566b22n3d
5: 0x10e47c8e2 - rust_begin_unwind
6: 0x10e49e62c - failure::begin_unwind::h4e97151c53e68d96j5j
7: 0x10e2bd0fc - option::Option<T>::unwrap::h2778475912063396917
8: 0x10e2bcf09 - json::Decoder::pop::hab5b5f6e228e32aftQd
9: 0x10e31f5c7 - json::Decoder...Decoder<DecoderError>::read_struct::h14270248516275819116
#![feature(phase, macro_rules)]
extern crate debug;
#[phase(plugin, link)] extern crate log;
extern crate serialize;
pub use serialize::{ Decodable, Decoder, Encoder, Encodable,};
#[path="../src/json.rs"]
mod json;
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::local_data;
trait Locale {
fn to_upper(&self, s: &str) {}
}
struct Indifferent;
impl Locale for Indifferent {}