3 The tracking issue for this feature is: [#29646]
5 [#29646]: https://github.com/rust-lang/rust/issues/29646
7 ------------------------
9 With the `associated_consts` feature, you can define constants like this:
12 #![feature(associated_consts)]
23 assert_eq!(1, i32::ID);
27 Any implementor of `Foo` will have to define `ID`. Without the definition:
30 #![feature(associated_consts)]
43 error: not all trait items implemented, missing: `ID` [E0046]
48 A default value can be implemented as well:
51 #![feature(associated_consts)]
65 assert_eq!(1, i32::ID);
66 assert_eq!(5, i64::ID);
70 As you can see, when implementing `Foo`, you can leave it unimplemented, as
71 with `i32`. It will then use the default value. But, as in `i64`, we can also
72 add our own definition.
74 Associated constants don’t have to be associated with a trait. An `impl` block
75 for a `struct` or an `enum` works fine too:
78 #![feature(associated_consts)]