use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct WireSchema {
pub fields: Vec<FieldSpec>,
}
impl WireSchema {
pub fn new(fields: Vec<FieldSpec>) -> Self {
Self { fields }
}
pub fn field(&self, name: &str) -> Option<&FieldSpec> {
self.fields.iter().find(|f| f.name == name)
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct FieldSpec {
pub name: String,
pub dtype: String,
#[serde(default)]
pub nullable: bool,
}
impl FieldSpec {
pub fn new(name: impl Into<String>, dtype: impl Into<String>) -> Self {
Self { name: name.into(), dtype: dtype.into(), nullable: false }
}
pub fn nullable(mut self, nullable: bool) -> Self {
self.nullable = nullable;
self
}
}