Skip to content

Instantly share code, notes, and snippets.

fn iterator_ref(opt: &Option<bool>) -> Box<Iterator<u8>> {
match opt {
&Some(_) => box [1u8].iter().map(|n| *n) as Box<Iterator<u8>>,
&None => box [0u8].iter().map(|n| *n) as Box<Iterator<u8>>,
}
}
fn main() {
let mut myref = iterator_ref(&Some(true));
@apoelstra
apoelstra / gist:07d8f9c3b619b90f548c
Created June 27, 2014 21:23
println side effect?
fn serialize_iter<'a>(&'a self) -> SerializeIter<'a> {
/*
println!("serialize opt {:} as {:}", self.is_some(),
(match self {
&Some(ref dat) => SerializeIter {
data_iter: Some(box [1u8].iter().map(|n| *n) as Box<Iterator<u8>>),
sub_iter_iter: box vec![ dat as &Serializable ].move_iter(),
sub_iter: None,
sub_started: false
},
@apoelstra
apoelstra / gist:380034a1457f82bb6b9d
Created June 27, 2014 21:22
println side effect?
fn serialize_iter<'a>(&'a self) -> SerializeIter<'a> {
/*
println!("serialize opt {:} as {:}", self.is_some(),
(match self {
&Some(ref dat) => SerializeIter {
data_iter: Some(box [1u8].iter().map(|n| *n) as Box<Iterator<u8>>),
sub_iter_iter: box vec![ dat as &Serializable ].move_iter(),
sub_iter: None,
sub_started: false
},
@apoelstra
apoelstra / gist:0c5e05a2d57a91be3c0b
Created June 25, 2014 22:22
Stack overflow in Rust's type system
use std::io::{IoResult, InvalidInput, standard_error};
/// Serialization trait
trait Serial {
fn deserialize<I: Iterator<u8>>(iter: I) -> IoResult<Self>;
}
/// Serialization for Option<Serial>
impl<T:Serial> Serial for Option<T> {
// Rust Bitcoin Library
// Written in 2014 by
// Andrew Poelstra <apoelstra@wpsoftware.net>
//
// To the extent possible under law, the author(s) have dedicated all
// copyright and related and neighboring rights to this software to
// the public domain worldwide. This software is distributed without
// any warranty.
//
// You should have received a copy of the CC0 Public Domain Dedication
@apoelstra
apoelstra / gist:dc3e57b5ef5062ff36aa
Created June 24, 2014 21:39
Patricia Trie implementation (insert/delete/lookup)
// Rust Bitcoin Library
// Written in 2014 by
// Andrew Poelstra <apoelstra@wpsoftware.net>
//
// To the extent possible under law, the author(s) have dedicated all
// copyright and related and neighboring rights to this software to
// the public domain worldwide. This software is distributed without
// any warranty.
//
// You should have received a copy of the CC0 Public Domain Dedication
// Rust Bitcoin Library
// Written in 2014 by
// Andrew Poelstra <apoelstra@wpsoftware.net>
//
// To the extent possible under law, the author(s) have dedicated all
// copyright and related and neighboring rights to this software to
// the public domain worldwide. This software is distributed without
// any warranty.
//
// You should have received a copy of the CC0 Public Domain Dedication