Я хотел бы создать общую библиотеку (плагин) с функцией generi c. T может быть: u8, u16, u32, float, i8, i16, i32.
pub struct Api {}
impl Api {
pub fn write_to_slave<T>(&self, id: u32, value: T)
{
println!("write to slave id : {}, value: {}", id, value);
}
}
Ошибка:
|
18 | pub fn write_to_slave<T>(&self, id: u32, value: T)
| - help: consider restricting this bound: `T: std::fmt::Display`
19 | {
20 | println!("write to slave id : {}, value: {}", id, value);
| ^^^^^ `T` cannot be formatted with the default formatter
|
= help: the trait std::fmt::Display is not implemented for T
= note: in format strings you may be able to use {:?} (or {:#?} for pretty-print) instead
= note: required by std::fmt::Display::fmt```