From 853b61e12b02c6ee286677c881ff4b64e5d34ed3 Mon Sep 17 00:00:00 2001 From: TatriX <tatrics@gmail.com> Date: Mon, 25 Nov 2019 20:37:23 +0100 Subject: [PATCH] Migration to 2018 edition --- Cargo.toml | 1 + src/lib.rs | 58 +++++++++++++++++++++++++++--------------------------- 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5868f84..fcd762d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ repository = "https://github.com/mattyhall/rs-tiled.git" readme = "README.md" license = "MIT" authors = ["Matthew Hall <matthew@quickbeam.me.uk>"] +edition = "2018" keywords = ["tiled", "tmx", "map"] diff --git a/src/lib.rs b/src/lib.rs index 6879b68..294a97b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -52,7 +52,7 @@ macro_rules! get_attrs { macro_rules! parse_tag { ($parser:expr, $close_tag:expr, {$($open_tag:expr => $open_method:expr),* $(,)*}) => { loop { - match try!($parser.next().map_err(TiledError::XmlDecodingError)) { + match r#try!($parser.next().map_err(TiledError::XmlDecodingError)) { XmlEvent::StartElement {name, attributes, ..} => { if false {} $(else if name.local_name == $open_tag { @@ -143,12 +143,12 @@ impl std::error::Error for TiledError { TiledError::Other(ref s) => s.as_ref(), } } - fn cause(&self) -> Option<&std::error::Error> { + fn cause(&self) -> Option<&dyn std::error::Error> { match *self { TiledError::MalformedAttributes(_) => None, - TiledError::DecompressingError(ref e) => Some(e as &std::error::Error), - TiledError::Base64DecodingError(ref e) => Some(e as &std::error::Error), - TiledError::XmlDecodingError(ref e) => Some(e as &std::error::Error), + TiledError::DecompressingError(ref e) => Some(e as &dyn std::error::Error), + TiledError::Base64DecodingError(ref e) => Some(e as &dyn std::error::Error), + TiledError::XmlDecodingError(ref e) => Some(e as &dyn std::error::Error), TiledError::PrematureEnd(_) => None, TiledError::Other(_) => None, } @@ -216,7 +216,7 @@ fn parse_properties<R: Read>(parser: &mut EventReader<R>) -> Result<Properties, ); let t = t.unwrap_or("string".into()); - p.insert(k, try!(PropertyValue::new(t, v))); + p.insert(k, r#try!(PropertyValue::new(t, v))); Ok(()) }, }); @@ -270,25 +270,25 @@ impl Map { let mut layer_index = 0; parse_tag!(parser, "map", { "tileset" => | attrs| { - tilesets.push(try!(Tileset::new(parser, attrs, map_path))); + tilesets.push(r#try!(Tileset::new(parser, attrs, map_path))); Ok(()) }, "layer" => |attrs| { - layers.push(try!(Layer::new(parser, attrs, w, layer_index))); + layers.push(r#try!(Layer::new(parser, attrs, w, layer_index))); layer_index += 1; Ok(()) }, "imagelayer" => |attrs| { - image_layers.push(try!(ImageLayer::new(parser, attrs, layer_index))); + image_layers.push(r#try!(ImageLayer::new(parser, attrs, layer_index))); layer_index += 1; Ok(()) }, "properties" => |_| { - properties = try!(parse_properties(parser)); + properties = r#try!(parse_properties(parser)); Ok(()) }, "objectgroup" => |attrs| { - object_groups.push(try!(ObjectGroup::new(parser, attrs, Some(layer_index)))); + object_groups.push(r#try!(ObjectGroup::new(parser, attrs, Some(layer_index)))); layer_index += 1; Ok(()) }, @@ -393,11 +393,11 @@ impl Tileset { let mut tiles = Vec::new(); parse_tag!(parser, "tileset", { "image" => |attrs| { - images.push(try!(Image::new(parser, attrs))); + images.push(r#try!(Image::new(parser, attrs))); Ok(()) }, "tile" => |attrs| { - tiles.push(try!(Tile::new(parser, attrs))); + tiles.push(r#try!(Tile::new(parser, attrs))); Ok(()) }, }); @@ -441,7 +441,7 @@ impl Tileset { fn new_external<R: Read>(file: R, first_gid: u32) -> Result<Tileset, TiledError> { let mut tileset_parser = EventReader::new(file); loop { - match try!(tileset_parser.next().map_err(TiledError::XmlDecodingError)) { + match r#try!(tileset_parser.next().map_err(TiledError::XmlDecodingError)) { XmlEvent::StartElement { name, attributes, .. } => { @@ -486,11 +486,11 @@ impl Tileset { let mut tiles = Vec::new(); parse_tag!(parser, "tileset", { "image" => |attrs| { - images.push(try!(Image::new(parser, attrs))); + images.push(r#try!(Image::new(parser, attrs))); Ok(()) }, "tile" => |attrs| { - tiles.push(try!(Tile::new(parser, attrs))); + tiles.push(r#try!(Tile::new(parser, attrs))); Ok(()) }, }); @@ -674,11 +674,11 @@ impl Layer { let mut properties = HashMap::new(); parse_tag!(parser, "layer", { "data" => |attrs| { - tiles = try!(parse_data(parser, attrs, width)); + tiles = r#try!(parse_data(parser, attrs, width)); Ok(()) }, "properties" => |_| { - properties = try!(parse_properties(parser)); + properties = r#try!(parse_properties(parser)); Ok(()) }, }); @@ -784,11 +784,11 @@ impl ObjectGroup { let mut properties = HashMap::new(); parse_tag!(parser, "objectgroup", { "object" => |attrs| { - objects.push(try!(Object::new(parser, attrs))); + objects.push(r#try!(Object::new(parser, attrs))); Ok(()) }, "properties" => |_| { - properties = try!(parse_properties(parser)); + properties = r#try!(parse_properties(parser)); Ok(()) }, }); @@ -869,15 +869,15 @@ impl Object { Ok(()) }, "polyline" => |attrs| { - shape = Some(try!(Object::new_polyline(attrs))); + shape = Some(r#try!(Object::new_polyline(attrs))); Ok(()) }, "polygon" => |attrs| { - shape = Some(try!(Object::new_polygon(attrs))); + shape = Some(r#try!(Object::new_polygon(attrs))); Ok(()) }, "properties" => |_| { - properties = try!(parse_properties(parser)); + properties = r#try!(parse_properties(parser)); Ok(()) }, }); @@ -910,7 +910,7 @@ impl Object { ], TiledError::MalformedAttributes("A polyline must have points".to_string()) ); - let points = try!(Object::parse_points(s)); + let points = r#try!(Object::parse_points(s)); Ok(ObjectShape::Polyline { points: points }) } @@ -923,7 +923,7 @@ impl Object { ], TiledError::MalformedAttributes("A polygon must have points".to_string()) ); - let points = try!(Object::parse_points(s)); + let points = r#try!(Object::parse_points(s)); Ok(ObjectShape::Polygon { points: points }) } @@ -977,7 +977,7 @@ fn parse_animation<R: Read>(parser: &mut EventReader<R>) -> Result<Vec<Frame>, T let mut animation = Vec::new(); parse_tag!(parser, "animation", { "frame" => |attrs| { - animation.push(try!(Frame::new(attrs))); + animation.push(r#try!(Frame::new(attrs))); Ok(()) }, }); @@ -1034,7 +1034,7 @@ fn parse_data<R: Read>( fn parse_base64<R: Read>(parser: &mut EventReader<R>) -> Result<Vec<u8>, TiledError> { loop { - match try!(parser.next().map_err(TiledError::XmlDecodingError)) { + match r#try!(parser.next().map_err(TiledError::XmlDecodingError)) { XmlEvent::Characters(s) => { return base64::decode(s.trim().as_bytes()).map_err(TiledError::Base64DecodingError) } @@ -1073,7 +1073,7 @@ fn decode_gzip(data: Vec<u8>) -> Result<Vec<u8>, TiledError> { fn decode_csv<R: Read>(parser: &mut EventReader<R>) -> Result<Vec<Vec<LayerTile>>, TiledError> { loop { - match try!(parser.next().map_err(TiledError::XmlDecodingError)) { + match r#try!(parser.next().map_err(TiledError::XmlDecodingError)) { XmlEvent::Characters(s) => { let mut rows: Vec<Vec<LayerTile>> = Vec::new(); for row in s.split('\n') { @@ -1121,7 +1121,7 @@ fn convert_to_tile(all: &Vec<u8>, width: u32) -> Vec<Vec<LayerTile>> { fn parse_impl<R: Read>(reader: R, map_path: Option<&Path>) -> Result<Map, TiledError> { let mut parser = EventReader::new(reader); loop { - match try!(parser.next().map_err(TiledError::XmlDecodingError)) { + match r#try!(parser.next().map_err(TiledError::XmlDecodingError)) { XmlEvent::StartElement { name, attributes, .. } => { -- GitLab