Open faern opened 6 years ago
Yup, make perfect sense. Probably can be even done with backward compatibility by doing Request<T: DeserializeOwned = serde_json::Value>
A possible set of problems are things like Params::Array(Vec<Value>)
where each item in the vector could have a different type. At the moment the way I solve it in jsonrpc-client-core
is that I let the T
represent the tuple of all types. so If I have a String
and u64
as arguments to a method then T
is (String, u64)
.
It basically works because tuples are serialized with [...]
so it becomes a list in json. Not completely sure if this can be generalized to the Request
object or not. So we would rather need something like Request<T: DeserializeOwned = jsonrpc_client_core::types::Params>
The current
Request
andResponse
objects ultimately hold on toserde_json::Value
for their actual values. This forces a user of those objects to first serialize/deserialize their typesT
to/from aserde_json::Value
between the wire representation and the finalT
representation. I have not done any performance benchmarks, but I guess serializing twice does cost quite a lot of extra resources.If these types had a generic it would be possible to have them deserialize directly from a wire format to their target type
T
. There would of course be some obstacles to overcome to make this work, but I think it could work. What do you think?