Skip to main content

csdif_core/
transform.rs

1// SPDX-License-Identifier: MIT
2// Copyright (c) 2025 Egon Kastelijn
3// file: src/transform.rs
4
5//! Trait-based transformation interface for mapping external data into CSDIF documents.
6
7use crate::model::CsdifDocument;
8use crate::error::CsdifError;
9
10/// Trait for mapping external data into a CSDIF document.
11///
12/// This trait should be implemented by any adapter that wants to convert
13/// its own input format into a valid CSDIF structure.
14pub trait CsdifMapper {
15    /// Converts the implementing type into a CSDIF document.
16    fn to_csdif(&self) -> Result<CsdifDocument, CsdifError>;
17}
18
19/// Generic transformation entry point.
20///
21/// This function delegates to the trait implementation of the input type.
22pub fn transform<T: CsdifMapper>(input: &T) -> Result<CsdifDocument, CsdifError> {
23    input.to_csdif()
24}
25