Ported to Rust master (pre-0.9)