I have two from_json() functions that are doing the same thing but are different in return type. It seems like there should be a way to avoid duplication, if its not terribly complex.
#[derive(Debug, Clone, PartialEq, serde_derive::Serialize, serde_derive::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct BasicWalletConfig {
#[serde(rename = "fileName")]
pub file_name: String,
pub reset: Option<bool>
}
impl BasicWalletConfig {
pub fn from_json(json: &str) -> Result<BasicWalletConfig, Error> {
let config: BasicWalletConfig = serde_json::from_str(json)?;
Ok(config)
}
}
#[derive(Debug, Clone, PartialEq, serde_derive::Serialize, serde_derive::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct IndyWalletConfig {
pub seed: string,
pub pool_file_name: string
}
impl IndyWalletConfig {
pub fn from_json(json: &str) -> Result<IndyWalletConfig, Error> {
let config: IndyWalletConfig = serde_json::from_str(json)?;
Ok(config)
}
}