1#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5pub enum DataType {
6 Bool,
7 U8,
8 U16,
9 U32,
10 U64,
11 I8,
12 I16,
13 I32,
14 I64,
15 F16,
16 F32,
17 F64,
18 Complex64,
19 Complex128,
20 String,
21 Bytes,
22}
23
24impl DataType {
25 pub fn size(&self) -> Option<usize> {
27 use DataType::*;
28 Some(match self {
29 Bool | U8 | I8 => 1,
30 U16 | I16 | F16 => 2,
31 U32 | I32 | F32 => 4,
32 U64 | I64 | F64 | Complex64 => 8,
33 Complex128 => 16,
34 String | Bytes => return None,
35 })
36 }
37}
38
39#[derive(Debug, Clone, Default, PartialEq)]
41pub struct ValueSemantics {
42 pub nodata: Option<f64>,
43 pub scale: Option<f64>,
44 pub offset: Option<f64>,
45 pub units: Option<String>,
46}
47
48#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
50pub enum Location {
51 Cell,
53 Node,
55 Edge,
57 Face,
59 Volume,
61}
62
63#[derive(Debug, Clone)]
68pub struct Field {
69 pub name: String,
70 pub dtype: DataType,
71 pub values: ValueSemantics,
72 pub domain: usize,
74 pub location: Location,
75 pub components: Option<usize>,
78}
79
80impl Field {
81 pub fn new(name: impl Into<String>, dtype: DataType, domain: usize) -> Self {
82 Self {
83 name: name.into(),
84 dtype,
85 values: ValueSemantics::default(),
86 domain,
87 location: Location::Cell,
88 components: None,
89 }
90 }
91}