Skip to content

Commit

Permalink
Use Display trait for Not, AlwaysTrue, and AlwaysFalse
Browse files Browse the repository at this point in the history
Previously the `VerificationMessage` for `Not`, `AlwaysTrue` and
`AlwaysFalse` were using the `VerificationOutput::value` to populate the
message, but now the `Display` implementation for these is used to
populate the message.
  • Loading branch information
nick-mobilecoin committed Mar 21, 2023
1 parent f040ce9 commit 48f4959
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions verifier/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,8 @@ impl<O> NotOutput<O> {
}
}

/// Will negate the output of the [`Verifier::verify()`] operation.
#[derive(Debug)]
/// Negated due to `Not`
#[derive(displaydoc::Display, Debug)]
pub struct Not<V> {
verifier: V,
}
Expand Down Expand Up @@ -350,19 +350,20 @@ impl<O, V: VerificationMessage<O>> VerificationMessage<NotOutput<O>> for Not<V>
) -> core::fmt::Result {
let status = choice_to_status_message(result.is_success());

write!(f, "{:pad$}{status} Negated due to `Not`:", "")?;
write!(f, "{:pad$}{status} {self}:", "")?;
let pad = pad + MESSAGE_INDENT;
writeln!(f)?;
self.verifier.fmt_padded(f, pad, &result.value.inner)
}
}

/// Success due to `AlwaysTrue`
#[derive(displaydoc::Display, Clone, Debug, Eq, Hash, PartialEq)]
/// Marker struct to ensure a node in the `VerificationOutput` was for an
/// `AlwaysTrue`
#[derive(Clone, Debug, Eq, Hash, PartialEq)]

Check warning on line 362 in verifier/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

verifier/src/lib.rs#L362

Added line #L362 was not covered by tests
pub struct AlwaysTrueValue;

/// Will always succeed for the [`Verifier::verify()`] operation.
#[derive(Clone, Debug, Eq, Hash, PartialEq, Default)]
/// Success due to `AlwaysTrue`
#[derive(displaydoc::Display, Clone, Debug, Eq, Hash, PartialEq, Default)]
pub struct AlwaysTrue;

impl<E> Verifier<E> for AlwaysTrue {
Expand All @@ -377,20 +378,20 @@ impl VerificationMessage<AlwaysTrueValue> for AlwaysTrue {
&self,
f: &mut Formatter<'_>,
pad: usize,
result: &VerificationOutput<AlwaysTrueValue>,
_result: &VerificationOutput<AlwaysTrueValue>,
) -> core::fmt::Result {
let status = SUCCESS_MESSAGE_INDICATOR;
let value = &result.value;
write!(f, "{:pad$}{status} {value}", "")
write!(f, "{:pad$}{status} {self}", "")
}
}

/// Failure due to `AlwaysFalse`
#[derive(displaydoc::Display, Clone, Debug, Eq, Hash, PartialEq)]
/// Marker struct to ensure a node in the `VerificationOutput` was for an
/// `AlwaysFalse`
#[derive(Clone, Debug, Eq, Hash, PartialEq)]

Check warning on line 390 in verifier/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

verifier/src/lib.rs#L390

Added line #L390 was not covered by tests
pub struct AlwaysFalseValue;

/// Will always fail for the [`Verifier::verify()`] operation.
#[derive(Clone, Debug, Eq, Hash, PartialEq, Default)]
/// Failure due to `AlwaysFalse`
#[derive(displaydoc::Display, Clone, Debug, Eq, Hash, PartialEq, Default)]
pub struct AlwaysFalse;

impl<E> Verifier<E> for AlwaysFalse {
Expand All @@ -405,11 +406,10 @@ impl VerificationMessage<AlwaysFalseValue> for AlwaysFalse {
&self,
f: &mut Formatter<'_>,
pad: usize,
result: &VerificationOutput<AlwaysFalseValue>,
_result: &VerificationOutput<AlwaysFalseValue>,
) -> core::fmt::Result {
let status = FAILURE_MESSAGE_INDICATOR;
let value = &result.value;
write!(f, "{:pad$}{status} {value}", "")
write!(f, "{:pad$}{status} {self}", "")
}
}

Expand Down

0 comments on commit 48f4959

Please sign in to comment.