utiles_core/
traits.rs

1//! Utiles traits
2
3use crate::parent::Parents;
4use crate::TileLike;
5use std::hash::Hash;
6
7/// `IsOk` trait for checking if a value is Ok and returns a result
8/// of self or an error
9pub trait IsOk: Sized {
10    /// Returns `Ok` if the value is `Ok` or an error
11    ///
12    /// # Errors
13    ///
14    /// Returns an error if the value is not `Ok`
15    fn ok(&self) -> Result<Self, crate::UtilesCoreError>;
16}
17
18/// `Coord2d` like trait for 2D coordinates has x/y getters
19pub trait Coord2dLike {
20    /// Returns the x value
21    fn x(&self) -> f64;
22
23    /// Returns the y value
24    fn y(&self) -> f64;
25}
26
27/// `LngLat` like trait
28pub trait LngLatLike: Coord2dLike {
29    /// Returns the longitude value
30    fn lng(&self) -> f64;
31
32    /// Returns the longitude value
33    fn lon(&self) -> f64 {
34        self.lng()
35    }
36
37    /// Returns the longitude value
38    fn longitude(&self) -> f64 {
39        self.lat()
40    }
41
42    /// Returns the latitude value
43    fn lat(&self) -> f64;
44
45    /// Returns the latitude value
46    fn latitude(&self) -> f64 {
47        self.lat()
48    }
49}
50
51pub trait TileParent: Eq + Hash + Copy + TileLike {
52    fn parent(&self, zoom: Option<u8>) -> Option<Self>
53    where
54        Self: Sized;
55
56    fn iter_parents(&self) -> Parents<Self> {
57        Parents {
58            current: self.parent(None),
59        }
60    }
61
62    #[must_use]
63    fn root() -> Self
64    where
65        Self: Sized;
66}
67
68pub trait TileChildren1: Eq + Hash + Copy + TileLike {
69    /// Returns direct children in Z order:
70    ///     1) top-left
71    ///     2) top-right
72    ///     3) bottom-left
73    ///     4) bottom-right
74    #[must_use]
75    fn children1(&self) -> [Self; 4];
76}