From 1d0743c1ffffc68bc05ca8eeb81c166192863f33 Mon Sep 17 00:00:00 2001 From: Kor Nielsen Date: Thu, 27 Jul 2023 16:56:14 -0700 Subject: [PATCH] Add "inline" feature for do_as_formatter() For some applications, using this feature can significantly reduce the size of the firmware image. --- Cargo.toml | 4 ++++ src/lib.rs | 2 ++ 2 files changed, 6 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 7394d01..d5a1455 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,10 @@ ufmt-write = { path = "write", version = "0.1.0" } # NOTE do NOT turn `std` into a default feature; this is a no-std first crate std = ["ufmt-write/std"] +# When enabled, do_as_formatter() will be inlined. This can reduce code size +# for some applications. +inline = [] + [[test]] name = "vs-std-write" required-features = ["std"] diff --git a/src/lib.rs b/src/lib.rs index d74072e..11ee63c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -410,6 +410,7 @@ where { type Writer = W; + #[cfg_attr(feature = "inline", inline(always))] fn do_as_formatter( &mut self, f: impl FnOnce(&mut Formatter<'_, W>) -> Result<(), W::Error>, @@ -424,6 +425,7 @@ where { type Writer = W; + #[cfg_attr(feature = "inline", inline(always))] fn do_as_formatter( &mut self, f: impl FnOnce(&mut Formatter<'_, W>) -> Result<(), W::Error>,