specta-elm 0.0.1

Yey! now your Rust types in Elm ;)
Documentation
use specta::{
    Types,
    datatype::{NamedReferenceType, Reference},
};

use crate::{Error, Exporter, module::ModuleImports, types::NDT};

pub fn render<'a, E: Exporter>(
    s: &mut String,
    imports: &'a mut ModuleImports,
    exporter: &E,
    types: &Types,
    r: &Reference,
    ndt: &'a NDT,
) -> Result<(), Error> {
    match r {
        Reference::Named(r) => match &r.inner {
            NamedReferenceType::Reference { .. } => {
                s.push_str(&exporter.format_reference(r, types));
                imports.require_specta(types.get(r).unwrap().name.to_string());
            }

            NamedReferenceType::Inline { dt, .. } => {
                ndt.render(s, imports, exporter, types, dt, None)?;
            }
            NamedReferenceType::Recursive(cycle) => {
                return Err(Error::infinite_recursive_inline_type(
                    ndt.path_string(),
                    format!("{r:?}"),
                    cycle.clone(),
                ));
            }
        },
        Reference::Opaque(r) => {
            return Err(Error::unsupported_opaque_reference(
                ndt.path_string(),
                r.clone(),
            ));
        }
    };
    Ok(())
}