mirror of
https://github.com/OMGeeky/confique.git
synced 2026-01-10 13:39:48 +01:00
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.
This commit is contained in:
@@ -95,7 +95,7 @@ impl Default for FormatOptions {
|
||||
/// ```
|
||||
pub fn template<C: Config>(options: FormatOptions) -> String {
|
||||
let mut out = Json5Formatter::new(&options);
|
||||
template::format::<C>(&mut out, options.general);
|
||||
template::format(&C::META, &mut out, options.general);
|
||||
out.finish()
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
use std::fmt;
|
||||
|
||||
use crate::{Config, meta::{Meta, FieldKind, LeafKind, Expr}};
|
||||
use crate::meta::{Meta, FieldKind, LeafKind, Expr};
|
||||
|
||||
|
||||
/// Trait abstracting over the format differences when it comes to formatting a
|
||||
@@ -146,9 +146,7 @@ impl Default for FormatOptions {
|
||||
/// If you don't need to use a custom formatter, rather look at the `format`
|
||||
/// functions in the format-specific modules (e.g. `toml::format`,
|
||||
/// `yaml::format`).
|
||||
pub(crate) fn format<C: Config>(out: &mut impl Formatter, options: FormatOptions) {
|
||||
let meta = &C::META;
|
||||
|
||||
pub(crate) fn format(meta: &Meta, out: &mut impl Formatter, options: FormatOptions) {
|
||||
// Print root docs.
|
||||
if options.comments {
|
||||
meta.doc.iter().for_each(|doc| out.comment(doc));
|
||||
|
||||
@@ -93,7 +93,7 @@ impl Default for FormatOptions {
|
||||
/// ```
|
||||
pub fn template<C: Config>(options: FormatOptions) -> String {
|
||||
let mut out = TomlFormatter::new(&options);
|
||||
template::format::<C>(&mut out, options.general);
|
||||
template::format(&C::META, &mut out, options.general);
|
||||
out.finish()
|
||||
}
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ impl Default for FormatOptions {
|
||||
/// ```
|
||||
pub fn template<C: Config>(options: FormatOptions) -> String {
|
||||
let mut out = YamlFormatter::new(&options);
|
||||
template::format::<C>(&mut out, options.general);
|
||||
template::format(&C::META, &mut out, options.general);
|
||||
out.finish()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user