gldf-rs 0.5.1

GLDF (General Lighting Data Format) parser and writer for Rust, specifically for the Rust/WASM target as such designed for JSON format
Documentation
#![warn(missing_docs)]
#![warn(rustdoc::broken_intra_doc_links)]
#![allow(non_local_definitions)]

/// The gldf header module (src/gldf/header.rs)
pub mod header;
pub use header::*;

/// The gldf general definitions module (src/gldf/general_definitions.rs)
pub mod general_definitions;

/// The gldf product definitions module (src/gldf/product_definitions.rs)
pub mod product_definitions;

/// The gldf meta information module (src/gldf/meta_information.rs)
/// not strictly needed but it is used in the gldf-sign
pub mod meta_information;

pub use general_definitions::*;
pub use product_definitions::*;
use serde::{Deserialize, Serialize};

fn get_xsnonamespaceschemalocation() -> String {
    "https://gldf.io/xsd/gldf/1.0.0-rc.3/gldf.xsd".to_string()
}

fn get_xmlns_xsi() -> String {
    "http://www.w3.org/2001/XMLSchema-instance".to_string()
}

/// Represents a GLDF (Global Lighting Data Format) product.
///
/// GLDFProduct is a Rust struct that models a product in the Global Lighting Data Format (GLDF).
/// It provides serialization and deserialization methods for working with GLDF XML data.
///
/// This struct is intended to represent GLDF products conforming to the schema specified at
/// `<https://gldf.io/xsd/gldf/1.0.0-rc.3/gldf.xsd>`
// Manual `Default` impl below — the derived one would zero-init the
// xmlns_xsi and xsnonamespaceschemaLocation fields to empty strings,
// which produces XML with `xmlns:xsi=""` and an empty schema attr.
// That round-trips through OUR parser (the serde defaults rehydrate
// the missing attrs) but breaks GLDF tooling that does proper XML
// namespace handling — including this repo's own reload path, which
// fails with "Failed to parse product.xml" when the namespace attr
// is the empty string. Regression: every wizard-built GLDF couldn't
// be re-imported.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename = "Root")]
pub struct GldfProduct {
    /// This field is not serialized or deserialized but can be used to store the path to the
    /// GLDF product file.
    #[serde(skip)]
    pub path: String,

    /// The XML namespace for xsi (XML Schema Instance).
    #[serde(rename = "@xmlns:xsi", default = "get_xmlns_xsi")]
    pub xmlns_xsi: String,

    /// The xsi:noNamespaceSchemaLocation attribute specifying the schema location.
    #[serde(
        rename = "@xsi:noNamespaceSchemaLocation",
        default = "get_xsnonamespaceschemalocation"
    )]
    pub xsnonamespaceschemalocation: String,

    /// The header of the GLDF product.
    #[serde(rename = "Header")]
    pub header: Header,

    /// The general definitions section of the GLDF product.
    #[serde(rename = "GeneralDefinitions")]
    pub general_definitions: GeneralDefinitions,

    /// The product definitions section of the GLDF product.
    #[serde(rename = "ProductDefinitions")]
    pub product_definitions: ProductDefinitions,
}

impl Default for GldfProduct {
    fn default() -> Self {
        Self {
            path: String::new(),
            xmlns_xsi: get_xmlns_xsi(),
            xsnonamespaceschemalocation: get_xsnonamespaceschemalocation(),
            header: Header::default(),
            general_definitions: GeneralDefinitions::default(),
            product_definitions: ProductDefinitions::default(),
        }
    }
}