Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trait HasDefault {
- fn default() -> Self;
- }
- struct DefaultOne;
- impl Default for DefaultOne {
- fn default() -> Self {
- DefaultOne{}
- }
- }
- struct DefaultTwo;
- impl Default for DefaultTwo {
- fn default() -> Self {
- DefaultTwo{}
- }
- }
- pub fn main() {
- println!("Hello");
- let v = vec![DefaultOne::default, DefaultTwo::default];
- let w = vec![DefaultOne::default(), DefaultTwo::default()];
- // Iterate over v or w using just methods in the Default trait
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement