Implement print = "code" on enums

This commit is contained in:
Guillaume Gomez 2025-08-03 00:32:13 +02:00 committed by René Kijewski
parent 80a4af7f2d
commit da850d736f
2 changed files with 9 additions and 4 deletions

View File

@ -12,7 +12,7 @@ use syn::{
use crate::generator::TmplKind;
use crate::input::{PartialTemplateArgs, TemplateArgs};
use crate::{CompileError, Context, build_template_item};
use crate::{CompileError, Context, Print, build_template_item};
/// Implement every integration for the given item
pub(crate) fn impl_everything(ast: &DeriveInput, buf: &mut Buffer) {
@ -367,6 +367,11 @@ pub(crate) fn build_template_enum(
&mut size_hint_arms,
);
}
let print_code = enum_args.as_ref().is_some_and(|args| {
args.print
.is_some_and(|print| print == Print::Code || print == Print::All)
});
if has_default_impl {
let size_hint = build_template_item(
buf,
@ -433,6 +438,9 @@ pub(crate) fn build_template_enum(
}),
enum_ast.span(),
);
if print_code {
eprintln!("{}", buf.to_string());
}
Ok(biggest_size_hint)
}

View File

@ -395,9 +395,6 @@ fn build_template_item(
}
let size_hint = template_to_string(buf, &input, &contexts, heritage.as_ref(), tmpl_kind)?;
if input.print == Print::Code || input.print == Print::All {
eprintln!("{}", buf.to_string());
}
Ok(size_hint)
}