csdif-core 0.1.3

Core library for modeling, validating, and transforming CSDIF data
Documentation
// SPDX-License-Identifier: MIT
// Copyright (c) 2025 Egon Kastelijn
// file: src/transform.rs

//! Trait-based transformation interface for mapping external data into CSDIF documents.

use crate::model::CsdifDocument;
use crate::error::CsdifError;

/// Trait for mapping external data into a CSDIF document.
///
/// This trait should be implemented by any adapter that wants to convert
/// its own input format into a valid CSDIF structure.
pub trait CsdifMapper {
    /// Converts the implementing type into a CSDIF document.
    fn to_csdif(&self) -> Result<CsdifDocument, CsdifError>;
}

/// Generic transformation entry point.
///
/// This function delegates to the trait implementation of the input type.
pub fn transform<T: CsdifMapper>(input: &T) -> Result<CsdifDocument, CsdifError> {
    input.to_csdif()
}