refactor TryFrom<Entry, ImmutableEntry>
parent
5653b1b107
commit
0f2fa6836f
|
@ -66,22 +66,25 @@ impl TryFrom<&Entry> for models::Entry {
|
|||
type Error = anyhow::Error;
|
||||
|
||||
fn try_from(e: &Entry) -> Result<Self, Self::Error> {
|
||||
let base_entry = models::Entry {
|
||||
identity: e.address()?.encode()?,
|
||||
entity: e.entity.encode()?,
|
||||
attribute: e.attribute.clone(),
|
||||
value_str: None,
|
||||
value_num: None,
|
||||
immutable: false,
|
||||
};
|
||||
|
||||
match e.value {
|
||||
EntryValue::Number(n) => Ok(models::Entry {
|
||||
identity: e.address()?.encode()?,
|
||||
entity: e.entity.encode()?,
|
||||
attribute: e.attribute.clone(),
|
||||
value_str: None,
|
||||
value_num: Some(n),
|
||||
immutable: false,
|
||||
..base_entry
|
||||
}),
|
||||
_ => Ok(models::Entry {
|
||||
identity: e.address()?.encode()?,
|
||||
entity: e.entity.encode()?,
|
||||
attribute: e.attribute.clone(),
|
||||
value_str: Some(e.value.to_string()?),
|
||||
value_num: None,
|
||||
immutable: false,
|
||||
..base_entry
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
@ -91,24 +94,10 @@ impl TryFrom<&ImmutableEntry> for models::Entry {
|
|||
type Error = anyhow::Error;
|
||||
|
||||
fn try_from(e: &ImmutableEntry) -> Result<Self, Self::Error> {
|
||||
match e.0.value {
|
||||
EntryValue::Number(n) => Ok(models::Entry {
|
||||
identity: e.0.address()?.encode()?,
|
||||
entity: e.0.entity.encode()?,
|
||||
attribute: e.0.attribute.clone(),
|
||||
value_str: None,
|
||||
value_num: Some(n),
|
||||
immutable: false,
|
||||
}),
|
||||
_ => Ok(models::Entry {
|
||||
identity: e.0.address()?.encode()?,
|
||||
entity: e.0.entity.encode()?,
|
||||
attribute: e.0.attribute.clone(),
|
||||
value_str: Some(e.0.value.to_string()?),
|
||||
value_num: None,
|
||||
immutable: false,
|
||||
}),
|
||||
}
|
||||
Ok(models::Entry {
|
||||
immutable: true,
|
||||
..models::Entry::try_from(&e.0)?
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue