Hide `NonEmpty` in `Debug` impl of `Bundle`

It is an implementation detail that isn't useful to include in the debug
output.
This commit is contained in:
Jack Grigg 2022-04-05 22:39:06 +00:00
parent caca664b20
commit 01d70ec875
1 changed files with 21 additions and 1 deletions

View File

@ -237,7 +237,7 @@ pub trait Authorization: fmt::Debug {
}
/// A bundle of actions to be applied to the ledger.
#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct Bundle<T: Authorization, V> {
/// The list of actions that make up this bundle.
actions: NonEmpty<Action<T::SpendAuth>>,
@ -253,6 +253,26 @@ pub struct Bundle<T: Authorization, V> {
authorization: T,
}
impl<T: Authorization, V: fmt::Debug> fmt::Debug for Bundle<T, V> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
/// Helper struct for debug-printing actions without exposing `NonEmpty`.
struct Actions<'a, T>(&'a NonEmpty<Action<T>>);
impl<'a, T: fmt::Debug> fmt::Debug for Actions<'a, T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_list().entries(self.0.iter()).finish()
}
}
f.debug_struct("Bundle")
.field("actions", &Actions(&self.actions))
.field("flags", &self.flags)
.field("value_balance", &self.value_balance)
.field("anchor", &self.anchor)
.field("authorization", &self.authorization)
.finish()
}
}
impl<T: Authorization, V> Bundle<T, V> {
/// Constructs a `Bundle` from its constituent parts.
pub fn from_parts(