我正在尝试序列化该方法的params
参数send
。
fn send<T>(method: &str, params: T) -> () {
println!("{:?}", serde_json::to_string(¶ms));
// Rest of actual code that works with 'method' and 'params'
}
fn main() {
send::<i32>("account", 44);
send::<&str>("name", "John");
}
但它给了我以下我无法解决的错误:
the trait bound `T: primitives::_IMPL_DESERIALIZE_FOR_Address::_serde::Serialize` is not satisfied
the trait `primitives::_IMPL_DESERIALIZE_FOR_Address::_serde::Serialize` is not implemented for `T`
help: consider adding a `where T: primitives::_IMPL_DESERIALIZE_FOR_Address::_serde::Serialize` boundrustc(E0277)
我猜这是因为它不知道需要序列化到的类型,尽管我在调用send
. 传递给的类型params
也可以是其他结构,而不仅仅是原始类型。