Closed hniksic closed 2 years ago
A macro I use often is
/// Fomat into InlinableString
macro_rules! ifomat {
($($args: tt)+) => ({
let mut is = InlinableString::new();
use std::fmt::Write;
wite! (&mut is, $($args)+) .expect ("!wite");
is})}
cf. https://crates.io/crates/fomat-macros
If std::fmt::Write
clashes with std::io::Write
then you can import it under a different name
use std::fmt::{Write as FmtWrite};
But that complains that InlinableString doesn't implement std::io::Write
For the record, the actual error message I'm seeing is
error[E0599]: no method named `write_fmt` found for mutable reference `&mut InlinableString` in the current scope
--> src/....rs:17:5
|
17 | write!(&mut out, "{}", n);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ method not found in `&mut InlinableString`
|
= help: items from traits can only be used if the trait is in scope
= note: the following trait is implemented but not in scope; perhaps add a `use` for it:
`use std::fmt::Write;`
Compiler hints the solution.
Is there a way to format an integer into an inlinable string? E.g. create a function with this signature:
n.into()
doesn't work. I expected to be able to usewrite!()
like this:But that complains that
InlinableString
doesn't implementstd::io::Write
.