use core::fmt::{self, Write as _};
pub fn truncated_str(input: impl Iterator<Item = char> + Clone, limit: usize) -> impl fmt::Display {
struct Iter<I>(I, usize);
impl<I: Iterator<Item = char> + Clone> fmt::Display for Iter<I> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut counter = 0;
for c in self.0.clone() {
f.write_char(c)?;
counter += 1;
if counter >= self.1 {
f.write_char('…')?;
break;
}
}
Ok(())
}
}
Iter(input, limit)
}
pub struct SipHasherBuild([u8; 16]);
impl SipHasherBuild {
pub fn new(seed: [u8; 16]) -> SipHasherBuild {
SipHasherBuild(seed)
}
}
impl core::hash::BuildHasher for SipHasherBuild {
type Hasher = siphasher::sip::SipHasher13;
fn build_hasher(&self) -> Self::Hasher {
siphasher::sip::SipHasher13::new_with_key(&self.0)
}
}