Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You 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.


neat, i didn't know that was possible




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: