1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// External includes.
// Standard includes.
// Internal includes.
use super::{
ContainsPosition, HasBottom, HasLeft, HasRight, HasTop, IntersectsPosition, PlacedObject, Shape,
};
/// Defines a 2D tile-based shape with a [`Position`](struct.Position.html).
///
/// "shape" is used instead of "polygon" as shapes do not necessarily have regular vertices or edges, nor do they necessarily conform to any regular geometric definition.
pub trait PlacedShape:
ContainsPosition
+ HasBottom
+ HasLeft
+ HasRight
+ HasTop
+ IntersectsPosition
+ PlacedObject
+ Shape
{
/// A helper method to allow structs implementing `Map` to be `Clone`'ed.
///
/// [https://users.rust-lang.org/t/solved-is-it-possible-to-clone-a-boxed-trait-object/1714/5](https://users.rust-lang.org/t/solved-is-it-possible-to-clone-a-boxed-trait-object/1714/5)
fn box_placed_shape_clone(&self) -> Box<dyn PlacedShape>;
/// Returns this `PlacedShape` as a `&dyn Shape`.
fn as_shape(&self) -> &dyn Shape;
}
impl Clone for Box<dyn PlacedShape> {
fn clone(&self) -> Box<dyn PlacedShape> {
self.box_placed_shape_clone()
}
}
impl<TShape: 'static> PlacedShape for TShape
where
TShape: Clone + ContainsPosition + IntersectsPosition + PlacedObject + Shape,
{
fn box_placed_shape_clone(&self) -> Box<dyn PlacedShape> {
Box::new((*self).clone())
}
fn as_shape(&self) -> &dyn Shape {
self
}
}