1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
extern crate alloc;

use alloc::string::String;
use alloc::vec::Vec;
use alloc::collections::BTreeMap;

/// Primitive types supported by Properties
#[derive(Debug, PartialEq)]
pub enum Primitive {
    /// String type utf8 encoded
    String(String),
    /// unsigned 64 bit integer
    Unsigned(u64),
    /// signed 64 bit integer
    Signed(i64),
    /// floating point number
    Float(f32),
    /// double precision floating point number
    Double(f64),
    /// boolean
    Boolean(bool),
    /// null
    Null,
}

/// When an array is used, it must be an array of the same type.
/// Arrays are also limited to primitives and objects of primitives
#[derive(Debug, PartialEq)]
pub enum ValueArray {
    /// Array of primitives
    Primitives(Vec<Primitive>),
    /// Array of objects that may only contain primitives
    Objects(Vec<BTreeMap<String, Primitive>>),
}

/// Supports primitive types `string`, `number`, `boolean`, `null`
/// May be an array of those types, or an object of those types
/// Object keys are always strings, values can be any basic type, an array, or a nested object.
/// Array values must all be the same type.
#[derive(Debug, PartialEq)]
pub enum Value {
    /// A primitive value
    Primitive(Primitive),
    /// An array of values
    Array(ValueArray),
    /// A nested object
    Object(BTreeMap<String, Value>),
}

/// Shape of a features properties object
pub type Properties = BTreeMap<String, Value>;
/// Shape of a feature's M-Values object
pub type MValue = Properties;

/// LineString Properties Shape
pub type LineStringMValues = Vec<MValue>;
/// MultiLineString MValues Shape
pub type MultiLineStringMValues = Vec<LineStringMValues>;
/// Polygon MValues Shape
pub type PolygonMValues = Vec<LineStringMValues>;
/// MultiPolygon MValues Shape
pub type MultiPolygonMValues = Vec<PolygonMValues>;

/// All possible M-Value shapes
#[derive(Debug, PartialEq)]
pub enum MValues {
    /// Single M-Value
    MValue(MValue),
    /// LineString M-Value
    LineStringMValues(LineStringMValues),
    /// MultiLineString M-Value
    MultiLineStringMValues(MultiLineStringMValues),
    /// Polygon M-Value
    PolygonMValues(PolygonMValues),
    /// MultiPolygon M-Value
    MultiPolygonMValues(MultiPolygonMValues),
}