diff --git a/src/animation.rs b/src/animation.rs index bf0d5364d7ba4126829672e3697380526b3ce87c..691b53196a603350fb8974594f361b6b16bbf996 100644 --- a/src/animation.rs +++ b/src/animation.rs @@ -2,7 +2,7 @@ use xml::attribute::OwnedAttribute; use crate::{error::TiledError, util::{get_attrs, XmlEventResult, parse_tag}}; -#[derive(Debug, PartialEq, Clone)] +#[derive(Debug, PartialEq, Clone, Copy)] pub struct Frame { pub tile_id: u32, pub duration: u32, diff --git a/src/cache.rs b/src/cache.rs index 4d670a152acdd7bf968e75b3fc00ccb9a5af4865..a193a1ae070074f69223431086829bd0c4d54ba4 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -21,6 +21,7 @@ pub trait ResourceCache { } /// A cache that identifies resources by their path in the user's filesystem. +#[derive(Debug)] pub struct FilesystemResourceCache { tilesets: HashMap<ResourcePathBuf, Arc<Tileset>>, } diff --git a/src/layers/group.rs b/src/layers/group.rs index 4e03fe62b213829be97fa5cd6f1c9d6025096b47..f4d135d260c8894591baf99c532945310e14dcf9 100644 --- a/src/layers/group.rs +++ b/src/layers/group.rs @@ -93,6 +93,7 @@ impl<'map> GroupLayer<'map> { } /// An iterator that iterates over all the layers in a group layer, obtained via [`GroupLayer::layers`]. +#[derive(Debug)] pub struct GroupLayerIter<'map> { map: &'map Map, group: &'map GroupLayerData, diff --git a/src/layers/image.rs b/src/layers/image.rs index de2d978bc8de23fc8223b76a7524a8e713712ab5..e75a92b0d367bca11591e9d09726bbcc49107b38 100644 --- a/src/layers/image.rs +++ b/src/layers/image.rs @@ -39,6 +39,7 @@ map_wrapper!(ImageLayer => ImageLayerData); impl<'map> ImageLayer<'map> { /// Get a reference to the image layer's image. + #[inline] pub fn image(&self) -> Option<&Image> { self.data.image.as_ref() } diff --git a/src/layers/mod.rs b/src/layers/mod.rs index ed0de12b3e4c8671fa3a6c891dc1d86dd3b41734..b0b006907f5ff85a39a7e035fea76c1a095825df 100644 --- a/src/layers/mod.rs +++ b/src/layers/mod.rs @@ -114,61 +114,73 @@ map_wrapper!(Layer => LayerData); impl<'map> Layer<'map> { /// Get a reference to the layer's name. + #[inline] pub fn name(&self) -> &str { self.data.name.as_ref() } /// Get the layer's id. + #[inline] pub fn id(&self) -> u32 { self.data.id } /// Whether this layer should be visible or not. + #[inline] pub fn visible(&self) -> bool { self.data.visible } /// Get the layer's x offset (in pixels). + #[inline] pub fn offset_x(&self) -> f32 { self.data.offset_x } /// Get the layer's y offset (in pixels). + #[inline] pub fn offset_y(&self) -> f32 { self.data.offset_y } /// Get the layer's x parallax factor. + #[inline] pub fn parallax_x(&self) -> f32 { self.data.parallax_x } /// Get the layer's y parallax factor. + #[inline] pub fn parallax_y(&self) -> f32 { self.data.parallax_y } /// Get the layer's opacity. + #[inline] pub fn opacity(&self) -> f32 { self.data.opacity } /// Get the layer's tint color. + #[inline] pub fn tint_color(&self) -> Option<Color> { self.data.tint_color } /// Get a reference to the layer's properties. + #[inline] pub fn properties(&self) -> &Properties { &self.data.properties } /// Get the layer's type. + #[inline] pub fn layer_type(&self) -> LayerType<'map> { LayerType::new(self.map, &self.data.layer_type) } } +#[derive(Debug)] pub enum LayerType<'map> { TileLayer(TileLayer<'map>), ObjectLayer(ObjectLayer<'map>), diff --git a/src/layers/object.rs b/src/layers/object.rs index efe2aa08f79036cdc8c36bd28a17626e7447a84e..c7265956286abdf340c24971ab5b34cc8b3ef3b3 100644 --- a/src/layers/object.rs +++ b/src/layers/object.rs @@ -64,6 +64,7 @@ impl<'map> ObjectLayer<'map> { } /// An iterator that iterates over all the objects in an object layer, obtained via [`ObjectLayer::objects`]. +#[derive(Debug)] pub struct Objects<'map> { map: &'map Map, data: &'map ObjectLayerData, @@ -91,6 +92,7 @@ impl<'map> Iterator for Objects<'map> { } impl<'map> ExactSizeIterator for Objects<'map> { + #[inline] fn len(&self) -> usize { self.data.objects.len() - self.index } diff --git a/src/layers/tile/finite.rs b/src/layers/tile/finite.rs index 6ad46e8ba7924f85aec068d51c878220e474ba8f..2e2c0cc30d987973ab4a829f58ad88ca6a166437 100644 --- a/src/layers/tile/finite.rs +++ b/src/layers/tile/finite.rs @@ -70,11 +70,13 @@ impl<'map> FiniteTileLayer<'map> { } /// Get the tile layer's width in tiles. + #[inline] pub fn width(&self) -> u32 { self.data.width } /// Get the tile layer's height in tiles. + #[inline] pub fn height(&self) -> u32 { self.data.height } diff --git a/src/layers/tile/mod.rs b/src/layers/tile/mod.rs index 6ff195be933c0b9d631f129aefc862825d85273c..5c3d27aa8d30d78f557f68afae36553035be418c 100644 --- a/src/layers/tile/mod.rs +++ b/src/layers/tile/mod.rs @@ -125,31 +125,37 @@ impl<'map> LayerTile<'map> { /// /// Use [`LayerTile::get_tile`] if you want to obtain the [`Tile`] that this layer tile is /// referencing. + #[inline] pub fn tileset_index(&self) -> usize { self.data.tileset_index } /// Get the layer tile's local id within its parent tileset. + #[inline] pub fn id(&self) -> u32 { self.data.id } /// Whether this tile is flipped on its Y axis (horizontally). + #[inline] pub fn flip_h(&self) -> bool { self.data.flip_h } /// Whether this tile is flipped on its X axis (vertically). + #[inline] pub fn flip_v(&self) -> bool { self.data.flip_v } /// Whether this tile is flipped diagonally. + #[inline] pub fn flip_d(&self) -> bool { self.data.flip_d } } +#[derive(Debug)] pub enum TileLayer<'map> { Finite(FiniteTileLayer<'map>), Infinite(InfiniteTileLayer<'map>), diff --git a/src/lib.rs b/src/lib.rs index 45a03f3d0bdfc2f24fbda962b25179b174dc8e18..0ec71af99d21dc2329c78bc14c52b511b50ad32c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,7 @@ +#![deny(unsafe_code)] +#![deny(missing_copy_implementations)] +#![deny(missing_debug_implementations)] + mod animation; mod cache; mod error; diff --git a/src/map.rs b/src/map.rs index 6eccabe5eb9cce272bfa00f8fd859f167453fe36..dcedbb2a0988004b0e6cc3c0b8296e67225ba09e 100644 --- a/src/map.rs +++ b/src/map.rs @@ -116,6 +116,7 @@ impl Map { } /// An iterator that iterates over all the layers in a map, obtained via [`Map::layers`]. +#[derive(Debug)] pub struct MapLayerIter<'map> { map: &'map Map, index: usize, diff --git a/src/objects.rs b/src/objects.rs index 646577aaef932face50e20f058021bea29cdbe8b..062270a5784867468e07cdbe4de2e10b8068fd54 100644 --- a/src/objects.rs +++ b/src/objects.rs @@ -172,6 +172,7 @@ map_wrapper!(Object => ObjectData); impl<'map> Object<'map> { /// Get the object's id. + #[inline] pub fn id(&self) -> u32 { self.data.id } @@ -185,51 +186,61 @@ impl<'map> Object<'map> { } /// Get a reference to the object's name. + #[inline] pub fn name(&self) -> &str { self.data.name.as_ref() } /// Get a reference to the object's type. + #[inline] pub fn obj_type(&self) -> &str { self.data.obj_type.as_ref() } /// Get the object's width. + #[inline] pub fn width(&self) -> f32 { self.data.width } /// Get the object's height. + #[inline] pub fn height(&self) -> f32 { self.data.height } /// Get the object's x. + #[inline] pub fn x(&self) -> f32 { self.data.x } /// Get object's y. + #[inline] pub fn y(&self) -> f32 { self.data.y } /// Get a reference to the object's rotation. + #[inline] pub fn rotation(&self) -> f32 { self.data.rotation } /// Whether the object should be visible or not. + #[inline] pub fn visible(&self) -> bool { self.data.visible } /// Get a reference to the object's shape. + #[inline] pub fn shape(&self) -> &ObjectShape { &self.data.shape } /// Get a reference to the object's properties. + #[inline] pub fn properties(&self) -> &Properties { &self.data.properties } diff --git a/src/tile.rs b/src/tile.rs index c99301b35e7ee80ea19395558d91f2d81dfbb338..4ef80dbc39f58cdc536b35fc36953a401044304e 100644 --- a/src/tile.rs +++ b/src/tile.rs @@ -24,6 +24,7 @@ pub(crate) struct TileData { probability: f32, } +#[derive(Debug)] pub struct Tile<'tileset> { pub(crate) tileset: &'tileset Tileset, pub(crate) data: &'tileset TileData, diff --git a/src/tileset.rs b/src/tileset.rs index 6e819883a28c6704b1bbbb33c16ef73afd26c67c..8745a80066b47d6e8d9ea88e298094b0980aa80a 100644 --- a/src/tileset.rs +++ b/src/tileset.rs @@ -106,6 +106,7 @@ impl Tileset { } /// Gets the tile with the specified ID from the tileset. + #[inline] pub fn get_tile(&self, id: u32) -> Option<Tile> { self.tiles.get(&id).map(|data| Tile::new(self, data)) } diff --git a/src/util.rs b/src/util.rs index 1afe902fe58cd8b9519e686c8c34c110c4da92f7..dadad0cf58523561fc5e9ef5125a76b0bdddd9be 100644 --- a/src/util.rs +++ b/src/util.rs @@ -55,18 +55,20 @@ macro_rules! parse_tag { /// Creates a new type that wraps an internal data type over along with a map. macro_rules! map_wrapper { ($name:ident => $data_ty:ty) => { - #[derive(Clone, PartialEq, Debug)] + #[derive(Clone, Copy, PartialEq, Debug)] pub struct $name<'map> { pub(crate) map: &'map $crate::Map, pub(crate) data: &'map $data_ty, } impl<'map> $name<'map> { + #[inline] pub(crate) fn new(map: &'map $crate::Map, data: &'map $data_ty) -> Self { Self { map, data } } /// Get the map this object is from. + #[inline] pub fn map(&self) -> &'map $crate::Map { self.map }