When using #[msgpack(default)], the macro generates code that calls to_string method. This is usually not an issue, but in a no_std environment, the ToString trait may not be available, which can cause a compilation error like the following:
Example code:
#![no_std]
use zerompk::{FromMessagePack, ToMessagePack};
#[derive(ToMessagePack, FromMessagePack)]
#[msgpack(map)]
pub struct TestData {
pub id: u8,
#[msgpack(default)]
pub retry: u8,
}
pub fn decode_packet(data: &[u8]) -> zerompk::Result<TestData> {
zerompk::from_msgpack(data)
}
Error message:
error[E0599]: no method named `to_string` found for reference `&str` in the current scope
--> src\lib.rs:5:25
|
5 | #[derive(ToMessagePack, FromMessagePack)]
| ^^^^^^^^^^^^^^^ method not found in `&str`
|
= help: items from traits can only be used if the trait is in scope
= note: this error originates in the derive macro `FromMessagePack` (in Nightly builds, run with -Z macro-backtrace for more info)
help: trait `ToString` which provides `to_string` is implemented but not in scope; perhaps you want to import it
|
3 + use alloc::string::ToString;
|
When using
#[msgpack(default)], the macro generates code that callsto_stringmethod. This is usually not an issue, but in a no_std environment, theToStringtrait may not be available, which can cause a compilation error like the following:Example code:
Error message: