use serde::{Deserialize, Serialize};
use crate::{contents_equal, is_false, Field};
#[derive(Debug, Clone, Default, Serialize, Deserialize, Eq)]
#[must_use]
#[non_exhaustive]
pub struct StructDefinition {
pub name: String,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub fields: Vec<Field>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[serde(default, skip_serializing_if = "is_false")]
pub imported: bool,
}
impl PartialEq for StructDefinition {
fn eq(&self, other: &Self) -> bool {
self.name == other.name && contents_equal(&self.fields, &other.fields)
}
}
impl StructDefinition {
pub fn new<T: Into<String>>(name: T, fields: Vec<Field>, description: Option<String>) -> Self {
Self {
name: name.into(),
fields,
imported: false,
description,
}
}
}