| 31 | pub struct FmtStack(pub Stack); |
| 32 | impl fmt::Display for FmtStack { |
| 33 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 34 | let mut iter = self.0.iter_str().enumerate().peekable(); |
| 35 | write!(f, "\n0:\t\t ")?; |
| 36 | while let Some((index, mut item)) = iter.next() { |
| 37 | if item.is_empty() { |
| 38 | write!(f, " [] ")?; |
| 39 | } else { |
| 40 | item.reverse(); |
| 41 | write!(f, "0x{:8}", item.as_hex())?; |
| 42 | } |
| 43 | if iter.peek().is_some() { |
| 44 | if (index + 1) % f.width().unwrap_or(4) == 0 { |
| 45 | write!(f, "\n{}:\t\t", index + 1)?; |
| 46 | } |
| 47 | write!(f, " ")?; |
| 48 | } |
| 49 | } |
| 50 | Ok(()) |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | impl FmtStack { |