Skip to content

Commit 20f0379

Browse files
Change template::format to not be generic over C
This potentially improves compile times a bit. The only thing the function needs is the `META` structure of `C`, which can be passed from the outside. The function is still generic over the formatter, but only three specific ones are passed. So maybe it's just compiled for those three already? One might also think about using dynamic dispatch for the formatter. Though compile times are likely dominated by all the generated code, especially the serde-derive code.
1 parent 2c19c0e commit 20f0379

File tree

4 files changed

+5
-7
lines changed

4 files changed

+5
-7
lines changed

src/json5.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl Default for FormatOptions {
9595
/// ```
9696
pub fn template<C: Config>(options: FormatOptions) -> String {
9797
let mut out = Json5Formatter::new(&options);
98-
template::format::<C>(&mut out, options.general);
98+
template::format(&C::META, &mut out, options.general);
9999
out.finish()
100100
}
101101

src/template.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
use std::fmt;
88

9-
use crate::{Config, meta::{Meta, FieldKind, LeafKind, Expr}};
9+
use crate::meta::{Meta, FieldKind, LeafKind, Expr};
1010

1111

1212
/// Trait abstracting over the format differences when it comes to formatting a
@@ -146,9 +146,7 @@ impl Default for FormatOptions {
146146
/// If you don't need to use a custom formatter, rather look at the `format`
147147
/// functions in the format-specific modules (e.g. `toml::format`,
148148
/// `yaml::format`).
149-
pub(crate) fn format<C: Config>(out: &mut impl Formatter, options: FormatOptions) {
150-
let meta = &C::META;
151-
149+
pub(crate) fn format(meta: &Meta, out: &mut impl Formatter, options: FormatOptions) {
152150
// Print root docs.
153151
if options.comments {
154152
meta.doc.iter().for_each(|doc| out.comment(doc));

src/toml.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl Default for FormatOptions {
9393
/// ```
9494
pub fn template<C: Config>(options: FormatOptions) -> String {
9595
let mut out = TomlFormatter::new(&options);
96-
template::format::<C>(&mut out, options.general);
96+
template::format(&C::META, &mut out, options.general);
9797
out.finish()
9898
}
9999

src/yaml.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl Default for FormatOptions {
9595
/// ```
9696
pub fn template<C: Config>(options: FormatOptions) -> String {
9797
let mut out = YamlFormatter::new(&options);
98-
template::format::<C>(&mut out, options.general);
98+
template::format(&C::META, &mut out, options.general);
9999
out.finish()
100100
}
101101

0 commit comments

Comments
 (0)