I'm creating an app that takes input from a file. The file will be edited by hand and read using toml-rs.
Here is an example:
foo = 7300
bar = "0x4563918244f40000"
This is the struct:
use serde::Deserialize;
use web3::types::U256;
#[derive(Deserialize)]
struct FooBar {
foo: U256,
bar: u32,
}
Here, U256 is a foreign type. It isn't part of my code base.
This works, but there are two problems. First, foo is scaled quantity. It represents "7.3 percent". Second, bar = "0x4563918244f40000" is a more than I really want to type.
You can always implement Deserialize manually instead of relying on the derive. By doing so, you can perform any conversion you need right in the deserialization code.