-
-
Save clonejo/6872732 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
mod.rs:13:15: 13:28 error: failed to find an implementation of trait std::rt::io::Reader for &std::rt::io::Reader<no-bounds> | |
mod.rs:13 return r.read_u8_(); |
This file contains hidden or 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::rt::io::Reader; | |
use std::rt::io::mem::MemReader; | |
use std::rt::io::extensions::ReaderByteConversions; | |
trait Decodable { | |
fn decode(r: &Reader) -> Self; | |
} | |
impl Decodable for u8 { | |
fn decode(r: &Reader) -> u8 { | |
return r.read_u8_(); | |
} | |
} | |
impl Decodable for u16 { | |
fn decode(r: &Reader) -> u16 { | |
return r.read_be_u16_(); | |
} | |
} | |
#[test] | |
fn test_encode_primitives() { | |
let buf: ~Reader = ~MemReader::new(~[17u8, 1u8, 3u8]) as ~Reader:Send; | |
{ | |
let ret: u8 = Decodable::decode(buf); | |
assert_eq!(ret, 17u8); | |
} | |
{ | |
let ret: u16 = Decodable::decode(buf); | |
assert_eq!(ret, 259u16); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment