1use std::fmt;
2
3#[derive(Clone)]
4pub struct Zoom(u8);
5
6pub static WORLD: &Zoom = &Zoom(1);
7pub static ZOOM_1: &Zoom = WORLD; pub static ZOOM_2: &Zoom = &Zoom(2);
9pub static ZOOM_3: &Zoom = &Zoom(3);
10pub static ZOOM_4: &Zoom = &Zoom(4);
11pub static CONTINENT: &Zoom = &Zoom(5);
12pub static ZOOM_5: &Zoom = CONTINENT; pub static ZOOM_6: &Zoom = &Zoom(6);
14pub static ZOOM_7: &Zoom = &Zoom(7);
15pub static ZOOM_8: &Zoom = &Zoom(8);
16pub static ZOOM_9: &Zoom = &Zoom(9);
17pub static CITY: &Zoom = &Zoom(10);
18pub static ZOOM_10: &Zoom = CITY; pub static ZOOM_11: &Zoom = &Zoom(11);
20pub static ZOOM_12: &Zoom = &Zoom(12);
21pub static ZOOM_13: &Zoom = &Zoom(13);
22pub static ZOOM_14: &Zoom = &Zoom(14);
23pub static STREETS: &Zoom = &Zoom(15);
24pub static ZOOM_15: &Zoom = STREETS; pub static ZOOM_16: &Zoom = &Zoom(16);
26pub static ZOOM_17: &Zoom = &Zoom(17);
27pub static ZOOM_18: &Zoom = &Zoom(18);
28pub static ZOOM_19: &Zoom = &Zoom(19);
29pub static BUILDINGS: &Zoom = &Zoom(20);
30pub static ZOOM_20: &Zoom = BUILDINGS; pub static ZOOM_21: &Zoom = &Zoom(21);
32
33impl Zoom {
34 pub fn new(zoom: u8) -> Self {
35 let clamp_zoom = if zoom > 21 { 21 } else { zoom };
36 Zoom(clamp_zoom)
37 }
38}
39
40impl fmt::Display for Zoom {
41 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
42 write!(f, "{}", self.0.to_string())
43 }
44}
45
46impl From<u8> for Zoom {
47 fn from(zoom: u8) -> Self {
48 Zoom::new(zoom)
49 }
50}
51
52impl From<i32> for Zoom {
53 fn from(zoom: i32) -> Self {
54 Zoom::new(zoom as u8)
55 }
56}