nil_core/continent/
field.rs1use crate::city::{City, PublicCity};
5use serde::{Deserialize, Serialize};
6use strum::EnumIs;
7
8#[derive(Clone, Debug, Default, Deserialize, Serialize, EnumIs)]
9#[serde(tag = "kind", rename_all = "kebab-case")]
10#[cfg_attr(feature = "typescript", derive(ts_rs::TS))]
11pub enum Field {
12 #[default]
13 Empty,
14 City {
15 city: Box<City>,
16 },
17}
18
19impl Field {
20 #[inline]
21 pub fn city(&self) -> Option<&City> {
22 if let Self::City { city } = self { Some(city) } else { None }
23 }
24
25 pub(super) fn city_mut(&mut self) -> Option<&mut City> {
26 if let Self::City { city } = self { Some(city) } else { None }
27 }
28}
29
30impl From<City> for Field {
31 fn from(city: City) -> Self {
32 Self::City { city: Box::new(city) }
33 }
34}
35
36#[derive(Clone, Debug, Default, Deserialize, Serialize, EnumIs)]
38#[serde(tag = "kind", rename_all = "kebab-case")]
39#[cfg_attr(feature = "typescript", derive(ts_rs::TS))]
40pub enum PublicField {
41 #[default]
42 Empty,
43 City {
44 city: PublicCity,
45 },
46}
47
48impl From<&Field> for PublicField {
49 fn from(field: &Field) -> Self {
50 match field {
51 Field::Empty => Self::Empty,
52 Field::City { city } => Self::City { city: PublicCity::from(&**city) },
53 }
54 }
55}