From 5ed55fb31191eb8057a57afcd8316335632c94c8 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 5 Sep 2020 23:12:19 +0100 Subject: [PATCH] debug RawToken better --- src/imports.rs | 2 +- src/spec.rs | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/imports.rs b/src/imports.rs index d09dd4a6..f38853f8 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -17,7 +17,7 @@ pub use std::iter; pub use std::iter::repeat_with; pub use std::collections::VecDeque; pub use std::num::Wrapping; -pub use std::cmp; +pub use std::cmp::{self,min,max}; pub use std::error::Error; pub use std::marker::PhantomData; pub use std::ops::{Deref,DerefMut}; diff --git a/src/spec.rs b/src/spec.rs index f13d6bcb..26943187 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -15,7 +15,7 @@ pub type Coord = isize; pub type Pos = [Coord; 2]; -#[derive(Clone,Debug,Eq,PartialEq,Ord,PartialOrd,Hash,Serialize,Deserialize)] +#[derive(Clone,Eq,PartialEq,Ord,PartialOrd,Hash,Serialize,Deserialize)] #[serde(transparent)] pub struct RawToken (pub String); @@ -104,6 +104,14 @@ mod implementation { use crate::imports::*; type Insn = crate::commands::MgmtGameInstruction; + impl Debug for RawToken { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let s = &self.0; + let len = min(5, s.len() / 2); + write!(f, "{:?}...", &s[0..len]) + } + } + #[typetag::serde(tag="access")] pub trait PlayerAccessSpec : Debug { fn token_mgi(&self, _player: PlayerId) -> Option { -- 2.30.2