display methods
parent
1d952b34dd
commit
6895b076be
|
@ -14,6 +14,7 @@ use log::{debug, trace};
|
||||||
use crate::addressing::Address;
|
use crate::addressing::Address;
|
||||||
use crate::hash::{decode, encode, hash, Hash, Hashable};
|
use crate::hash::{decode, encode, hash, Hash, Hashable};
|
||||||
use crate::models;
|
use crate::models;
|
||||||
|
use serde::export::Formatter;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Entry {
|
pub struct Entry {
|
||||||
|
@ -50,6 +51,12 @@ impl TryFrom<models::Entry> for Entry {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for InnerEntry {
|
||||||
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(f, "{} | {} | {}", self.target, self.key, self.value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl EntryValue {
|
impl EntryValue {
|
||||||
fn to_str(&self) -> Result<String> {
|
fn to_str(&self) -> Result<String> {
|
||||||
let (type_char, content) = match self {
|
let (type_char, content) = match self {
|
||||||
|
@ -62,6 +69,18 @@ impl EntryValue {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// unsafe unwraps!
|
||||||
|
impl std::fmt::Display for EntryValue {
|
||||||
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||||
|
let (entry_type, entry_value) = match self {
|
||||||
|
EntryValue::Address(address) => ("ADDRESS", encode(address.encode().unwrap())),
|
||||||
|
EntryValue::Value(value) => ("VALUE", serde_json::to_string(value).unwrap()),
|
||||||
|
EntryValue::Invalid => ("INVALID", "INVALID".to_string()),
|
||||||
|
};
|
||||||
|
write!(f, "{}: {}", entry_type, entry_value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl std::str::FromStr for EntryValue {
|
impl std::str::FromStr for EntryValue {
|
||||||
type Err = std::convert::Infallible;
|
type Err = std::convert::Infallible;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue