3 With the `associated_consts` feature, you can define constants like this:
6 #![feature(associated_consts)]
17 assert_eq!(1, i32::ID);
21 Any implementor of `Foo` will have to define `ID`. Without the definition:
24 #![feature(associated_consts)]
37 error: not all trait items implemented, missing: `ID` [E0046]
42 A default value can be implemented as well:
45 #![feature(associated_consts)]
59 assert_eq!(1, i32::ID);
60 assert_eq!(5, i64::ID);
64 As you can see, when implementing `Foo`, you can leave it unimplemented, as
65 with `i32`. It will then use the default value. But, as in `i64`, we can also
66 add our own definition.
68 Associated constants don’t have to be associated with a trait. An `impl` block
69 for a `struct` or an `enum` works fine too:
72 #![feature(associated_consts)]