diff --git a/examples/main.rs b/examples/main.rs index 5dc2bd3badcbd651247779d1cc8f42ffc2323c11..7c79161905d109ebf8a5e5066ef35f8a481a423f 100644 --- a/examples/main.rs +++ b/examples/main.rs @@ -1,14 +1,13 @@ extern crate serialize; extern crate tiled; -use std::old_io::{File, BufferedReader}; +use std::fs::File; use tiled::parse; fn main() { let file = File::open(&Path::new("assets/tiled_base64_zlib.tmx")).unwrap(); println!("Opened file"); - let reader = BufferedReader::new(file); - let map = parse(reader).unwrap(); + let map = parse(file).unwrap(); println!("{:?}", map); println!("{:?}", map.get_tileset_by_gid(22)); } diff --git a/src/lib.rs b/src/lib.rs index 0dfdc461e9ac1d4e37849de9302df617773588f9..50422ae3adbbe619ce69d9a606e4ecaf3ff3f9a7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -134,7 +134,7 @@ impl fmt::Display for TiledError { pub type Properties = HashMap<String, String>; -fn parse_properties<B: Buffer>(parser: &mut EventReader<B>) -> Result<Properties, TiledError> { +fn parse_properties<R: Read>(parser: &mut EventReader<R>) -> Result<Properties, TiledError> { let mut p = HashMap::new(); parse_tag!(parser, "properties", "property" => |attrs:Vec<OwnedAttribute>| { @@ -167,7 +167,7 @@ pub struct Map { } impl Map { - fn new<B: Buffer>(parser: &mut EventReader<B>, attrs: Vec<OwnedAttribute>) -> Result<Map, TiledError> { + fn new<R: Read>(parser: &mut EventReader<R>, attrs: Vec<OwnedAttribute>) -> Result<Map, TiledError> { let (c, (v, o, w, h, tw, th)) = get_attrs!( attrs, optionals: [("backgroundcolor", colour, |v:String| v.parse().ok())], @@ -258,7 +258,7 @@ pub struct Tileset { } impl Tileset { - fn new<B: Buffer>(parser: &mut EventReader<B>, attrs: Vec<OwnedAttribute>) -> Result<Tileset, TiledError> { + fn new<R: Read>(parser: &mut EventReader<R>, attrs: Vec<OwnedAttribute>) -> Result<Tileset, TiledError> { let ((s, m), (g, n, w, h)) = get_attrs!( attrs, optionals: [("spacing", spacing, |v:String| v.parse().ok()), @@ -294,7 +294,7 @@ pub struct Image { } impl Image { - fn new<B: Buffer>(parser: &mut EventReader<B>, attrs: Vec<OwnedAttribute>) -> Result<Image, TiledError> { + fn new<R: Read>(parser: &mut EventReader<R>, attrs: Vec<OwnedAttribute>) -> Result<Image, TiledError> { let (c, (s, w, h)) = get_attrs!( attrs, optionals: [("trans", trans, |v:String| v.parse().ok())], @@ -320,7 +320,7 @@ pub struct Layer { } impl Layer { - fn new<B: Buffer>(parser: &mut EventReader<B>, attrs: Vec<OwnedAttribute>, width: u32) -> Result<Layer, TiledError> { + fn new<R: Read>(parser: &mut EventReader<R>, attrs: Vec<OwnedAttribute>, width: u32) -> Result<Layer, TiledError> { let ((o, v), n) = get_attrs!( attrs, optionals: [("opacity", opacity, |v:String| v.parse().ok()), @@ -353,7 +353,7 @@ pub struct ObjectGroup { } impl ObjectGroup { - fn new<B: Buffer>(parser: &mut EventReader<B>, attrs: Vec<OwnedAttribute>) -> Result<ObjectGroup, TiledError> { + fn new<R: Read>(parser: &mut EventReader<R>, attrs: Vec<OwnedAttribute>) -> Result<ObjectGroup, TiledError> { let ((o, v, c), n) = get_attrs!( attrs, optionals: [("opacity", opacity, |v:String| v.parse().ok()), @@ -383,7 +383,7 @@ pub enum Object { } impl Object { - fn new<B: Buffer>(parser: &mut EventReader<B>, attrs: Vec<OwnedAttribute>) -> Result<Object, TiledError> { + fn new<R: Read>(parser: &mut EventReader<R>, attrs: Vec<OwnedAttribute>) -> Result<Object, TiledError> { let ((w, h, v), (x, y)) = get_attrs!( attrs, optionals: [("width", width, |v:String| v.parse().ok()), @@ -462,7 +462,7 @@ impl Object { } } -fn parse_data<B: Buffer>(parser: &mut EventReader<B>, attrs: Vec<OwnedAttribute>, width: u32) -> Result<Vec<Vec<u32>>, TiledError> { +fn parse_data<R: Read>(parser: &mut EventReader<R>, attrs: Vec<OwnedAttribute>, width: u32) -> Result<Vec<Vec<u32>>, TiledError> { let ((e, c), ()) = get_attrs!( attrs, optionals: [("encoding", encoding, |v| Some(v)), @@ -488,7 +488,7 @@ fn parse_data<B: Buffer>(parser: &mut EventReader<B>, attrs: Vec<OwnedAttribute> }; } -fn parse_base64<B: Buffer>(parser: &mut EventReader<B>) -> Result<Vec<u8>, TiledError> { +fn parse_base64<R: Read>(parser: &mut EventReader<R>) -> Result<Vec<u8>, TiledError> { loop { match parser.next() { Characters(s) => return s.trim() @@ -527,7 +527,7 @@ fn decode_gzip(data: Vec<u8>) -> Result<Vec<u8>, TiledError> { Ok(data) } -fn decode_csv<B: Buffer>(parser: &mut EventReader<B>) -> Result<Vec<Vec<u32>>, TiledError> { +fn decode_csv<R: Read>(parser: &mut EventReader<R>) -> Result<Vec<Vec<u32>>, TiledError> { loop { match parser.next() { Characters(s) => { @@ -569,7 +569,7 @@ fn convert_to_u32(all: &Vec<u8>, width: u32) -> Vec<Vec<u32>> { /// Parse a buffer hopefully containing the contents of a Tiled file and try to /// parse it. -pub fn parse<B: Buffer>(reader: B) -> Result<Map, TiledError> { +pub fn parse<R: Read>(reader: R) -> Result<Map, TiledError> { let mut parser = EventReader::new(reader); loop { match parser.next() { diff --git a/tests/lib.rs b/tests/lib.rs index c22adb6f8eadaab581d6031f59fd05a2ab4551d4..59147c68da6c1298482064be51472c53b23568e1 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -1,12 +1,11 @@ extern crate tiled; -use std::old_io::{File, BufferedReader}; +use std::fs::File; use tiled::{Map, TiledError, parse}; fn read_from_file(p: &Path) -> Result<Map, TiledError> { let file = File::open(p).unwrap(); - let reader = BufferedReader::new(file); - return parse(reader); + return parse(file); } #[test]