This limitation is annoying because if I move quack anywhere else, I'll have to repeat the Lots<Of::Things<Tediously>>: Declared part, which in my particular case is 5 lines of complex declarations.
Can I add "private" helper methods to trait implementations? If not, is there another way to move code into a helper method without duplicating the painfully large where clause?
type FromTuple<T> = From<(T,T)>;
pub trait Foo {}
impl<T> Foo for [T] where T: Copy + FromTuple<T> {}
error[E0404]: FromTuple is not a trait
and I think it can't handle T: Foo + Bar + Baz.
I can't add my helper method to the complicated type, as the method depends on bounds specified in where. AFAIK the best I can do is a generic method on the type, with all of where copy&pasted.
I don't have such a complicated method signature, but also faced that error. I liked the idea of using local functions:
impl fmt::Display for World {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn icon_for(world: &World, genome_id: GenomeId) -> char {
'◼' // Will add logic here
}
for line in self.entities.as_slice().chunks(self.width as usize) {
for &entity in line {
let symbol = match entity {
Entity::Nothing => ' ',
Entity::Cell(genome_id) => icon_for(self, genome_id),
Entity::Corpse(_) => '†',
};
write!(f, "{}", symbol)?;
}
write!(f, "\n")?;
}
Ok(())
}