Skip to main content

egml_core/model/base/
abstract_gml_kind.rs

1use crate::model::feature::AbstractFeatureKind;
2use crate::model::geometry::AbstractGeometryKind;
3
4#[derive(Debug, Clone, PartialEq)]
5pub enum AbstractGmlKind {
6    AbstractGeometryKind(AbstractGeometryKind),
7    AbstractFeatureKind(AbstractFeatureKind),
8}
9
10#[macro_export]
11macro_rules! impl_from_for_abstract_gml_kind {
12    ($variant:ident, $type:ty) => {
13        impl From<$type> for $crate::model::base::AbstractGmlKind {
14            #[allow(unreachable_code)]
15            fn from(x: $type) -> Self {
16                $crate::model::base::AbstractGmlKind::$variant(x.into())
17            }
18        }
19        $crate::impl_from_for_abstract_object_kind!(AbstractGmlKind, $type);
20    };
21    ($variant:ident) => {
22        $crate::impl_from_for_abstract_gml_kind!($variant, $variant);
23    };
24}
25
26#[macro_export]
27macro_rules! impl_try_from_for_abstract_gml_kind {
28    ($variant:ident, $type:ty) => {
29        impl TryFrom<$crate::model::base::AbstractGmlKind> for $type {
30            type Error = ();
31            #[allow(unreachable_code)]
32            fn try_from(x: $crate::model::base::AbstractGmlKind) -> Result<Self, ()> {
33                match x {
34                    $crate::model::base::AbstractGmlKind::$variant(k) => {
35                        k.try_into().map_err(|_| ())
36                    }
37                    #[allow(unreachable_patterns)]
38                    _ => Err(()),
39                }
40            }
41        }
42        $crate::impl_try_from_for_abstract_object_kind!(AbstractGmlKind, $type);
43    };
44    ($variant:ident) => {
45        $crate::impl_try_from_for_abstract_gml_kind!($variant, $variant);
46    };
47}
48
49impl_from_for_abstract_gml_kind!(AbstractGeometryKind);
50impl_from_for_abstract_gml_kind!(AbstractFeatureKind);
51impl_try_from_for_abstract_gml_kind!(AbstractGeometryKind);
52impl_try_from_for_abstract_gml_kind!(AbstractFeatureKind);