From: Ian Jackson Date: Sat, 5 Sep 2020 22:12:19 +0000 (+0100) Subject: debug RawToken better X-Git-Tag: otter-0.2.0~1016 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=5ed55fb31191eb8057a57afcd8316335632c94c8;p=otter.git debug RawToken better --- 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 {