Open dragonnn opened 3 years ago
I have the exact same question / problem.
looks like uWrite
is only implemented for String
when using std.
It would be good to add a alloc
feature and use alloc::string::String
instead, making this work better in no_std environments.
As a workaround one can make a newtype struct UString(String)
and implement uWrite
on it, something along these lines:
pub struct UString(pub String);
impl ufmt::uWrite for UString {
type Error = core::convert::Infallible;
fn write_str(&mut self, s: &str) -> Result<(), core::convert::Infallible> {
self.0.push_str(s);
Ok(())
}
}
impl ufmt::uDisplay for UString {
fn fmt<W>(&self, f: &mut ufmt::Formatter<'_, W>) -> Result<(), W::Error>
where
W: ufmt::uWrite + ?Sized,
{
<str as ufmt::uDisplay>::fmt(&self.0, f)
}
}
It would be good to add a
alloc
feature and usealloc::string::String
instead, making this work better in no_std environments.
Yup! That would be perfect
Hi! I am trying to craft a environment for my embedded board. Trying to use ufmt uwrite! with alloc::string::String but getting such errors:
I already have a working allocator since the underlying system is based on nuttx and I just use libc_alloc with uses malloc and other options from directly nuttx libc. I would be really grateful for any help, I am stuck with that currently