3 ms·
ruby is closer to what i meant because you can't add methods to rust's iterator, can you? but people add stuff to enumerable all the time
by kragen 3y ago
ruby is closer to what i meant because you can't add methods to rust's iterator, can you? but people add stuff to enumerable all the time
- josephg 3y agoYou can! trait MyIterHelpers: Iterator { fn dance(&self) { println!("wheee"); } } // And tell rust that all Iterators are also MyIterHelpers. impl<I: Iterator> MyIterHelpers for I {} The one caveat is that using it in a different context will need a use crate::MyIterHelpers; line, so the namespace isn't polluted.
- kragen 3y agoneat, i didn't know that was possible