cl-structures: (ab)use the Display trait to print a numbered, sorted list of interned strings.
This commit is contained in:
parent
28f9048087
commit
5662bd8524
@ -185,6 +185,24 @@ pub mod string_interner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for StringInterner<'_> {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
let Ok(keys) = self.keys.read() else {
|
||||||
|
return write!(f, "Could not lock StringInterner key map.");
|
||||||
|
};
|
||||||
|
let mut keys: Vec<_> = keys.iter().collect();
|
||||||
|
keys.sort();
|
||||||
|
|
||||||
|
writeln!(f, "Keys:")?;
|
||||||
|
for (idx, key) in keys.iter().enumerate() {
|
||||||
|
writeln!(f, "{idx}:\t\"{key}\"")?
|
||||||
|
}
|
||||||
|
writeln!(f, "Count: {}", keys.len())?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// # Safety:
|
// # Safety:
|
||||||
// This is fine because StringInterner::get_or_insert(v) holds a RwLock
|
// This is fine because StringInterner::get_or_insert(v) holds a RwLock
|
||||||
// for its entire duration, and doesn't touch the non-(Send+Sync) arena
|
// for its entire duration, and doesn't touch the non-(Send+Sync) arena
|
||||||
|
Loading…
Reference in New Issue
Block a user