#![allow(incomplete_features)]
#![feature(specialization)]
#![feature(let_chains)]
pub use core::convert::AsRef;
use std::ffi::OsStr;
use type_reflect_macros;
use std::fs::File;
pub use std::io::Write;
pub use std::path::Path;
pub use ts_quote::ts_string;
pub use type_reflect_macros::export_types;
pub use type_reflect_macros::Reflect;
pub mod struct_type;
pub use struct_type::*;
pub use type_reflect_core::*;
pub mod zod;
pub use zod::Zod;
pub mod rust;
pub use rust::Rust;
pub mod enum_type;
pub use enum_type::*;
pub mod alias_type;
pub use alias_type::*;
pub mod type_script;
pub use type_script::TypeScript;
pub mod ts_validation;
pub use ts_validation::TSValidation;
pub mod ts_format;
pub use ts_format::TSFormat;
pub use serde::{Deserialize, Serialize};
pub use serde_json;
pub trait Emittable {
fn emit_with<E: TypeEmitter>(emitter: &mut E) -> String;
}
pub fn init_destination_file<P: std::fmt::Debug + Clone, Pref>(
path: P,
prefix: Pref,
) -> Result<File, std::io::Error>
where
P: AsRef<Path>,
Pref: AsRef<[u8]>,
{
let mut file = match File::create(path.clone()) {
Ok(file) => file,
Err(err) => {
eprintln!("Error creating file: {:?}", path);
return Err(err);
}
};
file.write_all(prefix.as_ref())?;
Ok(file)
}
pub fn write_postfix<P: std::fmt::Debug + Clone, Post>(
path: P,
postfix: Post,
) -> Result<(), std::io::Error>
where
P: AsRef<Path>,
Post: AsRef<[u8]>,
{
let mut file = std::fs::OpenOptions::new()
.write(true)
.append(true)
.open(path)?;
file.write_all(postfix.as_ref())?;
Ok(())
}
pub trait TypeEmitter {
fn finalize<P>(&mut self, path: P) -> Result<(), std::io::Error>
where
P: AsRef<OsStr>;
fn prefix(&mut self) -> String;
fn emit<T: Emittable>(&mut self) -> String
where
Self: Sized,
{
T::emit_with::<Self>(self)
}
fn emit_struct<T>(&mut self) -> String
where
T: StructType;
fn emit_enum<T>(&mut self) -> String
where
T: EnumReflectionType;
fn emit_alias<T>(&mut self) -> String
where
T: AliasType;
}
pub trait RustType {
fn emit_rust(&self) -> String;
}