1#[derive(Debug, thiserror::Error)]
2pub enum Error {
3 #[error("Expected a {expected}, but found a {found}")]
4 MismatchedGeometry {
5 expected: &'static str,
6 found: &'static str,
7 },
8}
9
10#[cfg(test)]
11mod test {
12 use crate::{Geometry, Point, Rect};
13 use alloc::string::ToString;
14 use core::convert::TryFrom;
15
16 #[test]
17 fn error_output() {
18 let point = Point::new(1.0, 2.0);
19 let point_geometry = Geometry::from(point);
20
21 let rect = Rect::new(Point::new(1.0, 2.0), Point::new(3.0, 4.0));
22 let rect_geometry = Geometry::from(rect);
23
24 Point::try_from(point_geometry).expect("failed to unwrap inner enum Point");
25
26 let failure = Point::try_from(rect_geometry).unwrap_err();
27 assert_eq!(
28 failure.to_string(),
29 "Expected a geo_types::geometry::point::Point, but found a geo_types::geometry::rect::Rect"
30 );
31 }
32}