Re:Dark side of ergonomics in Rust
by twic on Saturday April 14, 2018 @07:45AM
(#16836928)
Looking at this from a Rusty point of view, ownership rules make this possible. When this function creates but button, it owns it. To mutate it (addLabel/setAlignment/sizeToFit), it has to own it. But for it to continue to exist after the function returns, something else has to own it. Therefore, Window::addSubview has to take ownership of the button, and so, has to come last:
In that situation, the button's destructor absolutely could delete itself.