Skip to content

Commit

Permalink
fix: PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuthor committed Jun 30, 2023
1 parent b71b362 commit 9b7dde9
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ pub struct Location(Vec<u8>);

impl_byte_vector!(Location);

impl Display for Location {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "location: {}", STANDARD.encode(self))
}
}

/// The value indexed by a [`Keyword`]. It can be either a [`Location`] or
/// another [`Keyword`] in case the searched [`Keyword`] was a tree node.
///
Expand All @@ -197,6 +203,15 @@ pub enum IndexedValue {
NextKeyword(Keyword),
}

impl Display for IndexedValue {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Location(location) => write!(f, "location: {}", STANDARD.encode(location)),
Self::NextKeyword(keyword) => write!(f, "next keyword: {}", STANDARD.encode(keyword)),
}
}
}

impl IndexedValue {
/// Serializes the [`IndexedValue`].
///
Expand Down Expand Up @@ -468,7 +483,7 @@ impl<const UID_LENGTH: usize> Display for Uids<UID_LENGTH> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut output = String::new();
for uid in self.clone() {
output = format!("uid: {}\n{output}", STANDARD.encode(uid));
output.push_str(&format!("uid: {}\n", STANDARD.encode(uid)));
}
write!(f, "{output}")
}
Expand All @@ -484,11 +499,11 @@ impl<const UID_LENGTH: usize> Display for EncryptedTable<UID_LENGTH> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut output = String::new();
for (uid, value) in self.clone() {
output = format!(
"uid: {}, value: {}, \n{output}",
output.push_str(&format!(
"uid: {}, value: {}, \n",
STANDARD.encode(uid),
STANDARD.encode(value),
);
));
}
write!(f, "{output}")
}
Expand Down Expand Up @@ -578,12 +593,11 @@ impl<const UID_LENGTH: usize> Display for EncryptedMultiTable<UID_LENGTH> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut output = String::new();
for (uid, value) in self.0.clone() {
output = format!(
"uid: {}, values: {}, \n{}",
output.push_str(&format!(
"uid: {}, values: {}, \n",
STANDARD.encode(uid),
STANDARD.encode(value),
output,
);
));
}
write!(f, "{output}")
}
Expand Down Expand Up @@ -672,19 +686,19 @@ impl<const UID_LENGTH: usize> Display for UpsertData<UID_LENGTH> {
for (uid, (old_value, new_value)) in self.0.clone() {
match old_value {
Some(old) => {
output = format!(
"uid: {} old_value: {} new_value: {}, \n{output}",
output.push_str(&format!(
"uid: {} old_value: {} new_value: {}, \n",
STANDARD.encode(uid),
STANDARD.encode(old),
STANDARD.encode(new_value)
)
));
}
None => {
output = format!(
"uid: {} old_value: '' new_value: {}, \n{output}",
output.push_str(&format!(
"uid: {} old_value: '' new_value: {}, \n",
STANDARD.encode(uid),
STANDARD.encode(new_value)
)
));
}
}
}
Expand Down

0 comments on commit 9b7dde9

Please sign in to comment.