1use serde::{Deserialize, Serialize};
9
10#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
12pub struct WireSchema {
13 pub fields: Vec<FieldSpec>,
14}
15
16impl WireSchema {
17 pub fn new(fields: Vec<FieldSpec>) -> Self {
18 Self { fields }
19 }
20
21 pub fn field(&self, name: &str) -> Option<&FieldSpec> {
22 self.fields.iter().find(|f| f.name == name)
23 }
24}
25
26#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
32pub struct FieldSpec {
33 pub name: String,
34 pub dtype: String,
35 #[serde(default)]
36 pub nullable: bool,
37}
38
39impl FieldSpec {
40 pub fn new(name: impl Into<String>, dtype: impl Into<String>) -> Self {
41 Self { name: name.into(), dtype: dtype.into(), nullable: false }
42 }
43
44 pub fn nullable(mut self, nullable: bool) -> Self {
45 self.nullable = nullable;
46 self
47 }
48}