Sometimes, I factor my code out into functions (or methods) just to find the compiler complains about it.

WHY?

Often, it happens because I try to return an Iterator or other Trait.

I’m still learning, but so far, I got these points about Rust functions:

- **You can’t return traits from functions**. Be specific, return something that implements the trait you need. For example, the return type “[SplitWhitespace](https://doc.rust-lang.org/std/str/struct.SplitWhitespace.html)” from function “[split_whitespace](https://doc.rust-lang.org/std/string/struct.String.html#method.split_whitespace)”. Very specific, right? But it implements “Iterator”. The function “[split](https://doc.rust-lang.org/std/string/struct.String.html#method.split)” returns the type “[Split](https://doc.rust-lang.org/std/str/struct.Split.html)” a different struct that also implements “Iterator”. Useful link: [implement iterator](https://doc.rust-lang.org/std/iter/index.html#implementing-iterator).
- **You can accept traits as arguments**, use and abuse that!

Rule of thumb, use the [Postel’s law](https://en.wikipedia.org/wiki/Robustness_principle): “Be conservative in what you send, be liberal in what you accept”.
