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

But the whole idea is that once a closure implements an interface its internal state is strongly isolated behind the abstraction barrier of the interface and no one knows or cares whatever state it has, if any. It is very CS 101.


Well, first of all, it's not a closure, it's a struct, though closures are syntax sugar for structs.

Second, what you said is true, but also not really relevant; mutability is part of the API in Rust, and so that is part of the interface.

To make it more concrete, https://doc.rust-lang.org/stable/std/iter/trait.Iterator.htm..., the protocol, takes &mut self. So it must be mutable. It's following the principle you're talking about.




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

Search: