pub fn from_fn<F, L>(f: F) -> FromFn<F>
Expand description
Construct a FormatInto implementation from a function.
ยงExamples
use genco::{quote, quote_in};
use genco::lang::{Lang, Rust};
use genco::tokens::{ItemStr, FormatInto, Tokens, from_fn, static_literal};
fn comment(s: impl Into<ItemStr> + Copy) -> impl FormatInto<Rust> + Copy {
from_fn(move |tokens| {
let s = s.into();
quote_in!(*tokens => $(static_literal("//")) #s);
})
}
let c = comment("hello world");
let _: Tokens<Rust> = quote!($c $['\n'] $c);