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