2

I see some Rust code that looks like this:

#![feature(default_type_params)]

After a lot of Googling, I get nothing about it. What is this? When should I use it?

1 Answer 1

5

It is enabling feature called default type parameters, but you already know that, so let me show you an example:

#![feature(default_type_params)]

struct Foo<A=(int, char)> { // default type parameter here!
    a: A
}

fn default_foo(x: Foo) {
   let (_i, _c): (int, char) = x.a;
}

fn main() {
   default_foo(Foo { a: (1, 'a') })
}

Without default type parameters, you would need to explicitly set parameters:

struct Foo<A> {
    a: A
}

fn default_foo(x: Foo<(int, char>)) {
   let (_i, _c): (int, char) = x.a;
}

fn main() {
   default_foo(Foo { a: (1, 'a') })
}

Example stolen from here: https://github.com/rust-lang/rust/pull/11217

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.