#![warn(
unknown_lints,
// ---------- Stylistic
absolute_paths_not_starting_with_crate,
elided_lifetimes_in_paths,
explicit_outlives_requirements,
macro_use_extern_crate,
nonstandard_style, /* group */
noop_method_call,
rust_2018_idioms,
single_use_lifetimes,
trivial_casts,
trivial_numeric_casts,
// ---------- Future
future_incompatible, /* group */
rust_2021_compatibility, /* group */
// ---------- Public
missing_debug_implementations,
// missing_docs,
unreachable_pub,
// ---------- Unsafe
unsafe_code,
unsafe_op_in_unsafe_fn,
// ---------- Unused
unused, /* group */
)]
#![deny(
// ---------- Public
exported_private_dependencies,
// ---------- Deprecated
anonymous_parameters,
bare_trait_objects,
ellipsis_inclusive_range_patterns,
// ---------- Unsafe
deref_nullptr,
drop_bounds,
dyn_drop,
)]
use sdml_core::{error::Error, model::modules::Module, store::ModuleStore};
use std::{fmt::Debug, fs::OpenOptions, io::Cursor, io::Write, path::PathBuf};
pub trait Generator: Default {
type Options: Default + Debug;
fn generate<W>(
&mut self,
module: &Module,
cache: &impl ModuleStore,
path: Option<PathBuf>,
writer: &mut W,
) -> Result<(), Error>
where
W: Write + Sized,
{
self.generate_with_options(module, cache, Default::default(), path, writer)
}
fn generate_to_string(
&mut self,
module: &Module,
cache: &impl ModuleStore,
options: Self::Options,
path: Option<PathBuf>,
) -> Result<String, Error> {
let mut buffer = Cursor::new(Vec::new());
self.generate_with_options(module, cache, options, path, &mut buffer)?;
Ok(String::from_utf8(buffer.into_inner())?)
}
fn generate_to_file(
&mut self,
module: &Module,
cache: &impl ModuleStore,
options: Self::Options,
path: &PathBuf,
) -> Result<(), Error> {
let mut file = OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.open(path)?;
self.generate_with_options(module, cache, options, Some(path.clone()), &mut file)
}
fn generate_with_options<W>(
&mut self,
module: &Module,
cache: &impl ModuleStore,
options: Self::Options,
path: Option<PathBuf>,
writer: &mut W,
) -> Result<(), Error>
where
W: Write + Sized;
}
#[macro_use]
mod macros;
mod errors;
mod exec;
pub mod color;
pub mod actions;
pub mod convert;
pub mod draw;