[I posted this yesterday, but since it didn't show up, I'm re-posting it. Sorry if it's a double post]
I'd like to be able to use the non-virtual interface (NVI) idiom: http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Non-Virtual_Interface The following two new features are needed to accomplish this: 1) To set trait-methods private (accessible only to other methods of that trait) 2) To set default (provided) trait-methods non-overridable It could work something like this (deltas are the 'final' keyword and the 'priv' trait-methods): pub trait Tr { final fn foo_and_back_again(&mut self) { self.foo(); self.de_foo(); } priv fn foo(&mut self); priv fn de_foo(&mut self); } pub struct St { n: int } impl Tr for St { fn foo_and_back_again(&mut self) {} // error: can't override a final method priv fn foo(&mut self) { self.n += 10; } priv fn de_foo(&mut self) { self.n -= 10; } } fn main() { let mut st = St { n: 11 }; st.foo_and_back_again(); // OK st.foo(); // error: foo is private to Tr st.de_foo(); // error: de_foo is private to Tr }
_______________________________________________ Rust-dev mailing list [email protected] https://mail.mozilla.org/listinfo/rust-dev
