What is the 'default' keyword means in rust?

While I was debugging my program, I came across the 'default' keyword in this line~/.rustup/toolchains/.../lib/rustlib/src/rust/library/alloc/src/vec.rs:2345.

impl<T, I> SpecFromIter<T, I> for Vec<T>                                                                                                                    │
│   2342        where                                                                                                                                                       │
│   2343            I: Iterator<Item = T>,                                                                                                                                  │
│   2344        {                                                                                                                                                           │
│  >2345            default fn from_iter(iterator: I) -> Self {                                                                                                             │
│   2346                SpecFromIterNested::from_iter(iterator)                                                                                                             │
│   2347            }                                                                                                                                                       │
│   2348        }

There is no documentation about this keyword in rust book or rust reference. Even google also doesn't give results about this keyword. So, what is this keyword and why is it present here?

This is part of an unstable feature called Specialization. It's experimental, and can be used only in nightly builds of the Rust compiler.

2 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.