I read the document of Rust core library and found that core implement the primitives like i32, bool, usize...
And I check the source code, it do so basically like:
impl i32 {
// const number
int_impl! { i32, i32, u32, 32, 31, -2147483648, 2147483647, 8, "0x10000b3", "0xb301",
"0x12345678", "0x78563412", "0x1e6a2c48", "[0x78, 0x56, 0x34, 0x12]",
"[0x12, 0x34, 0x56, 0x78]", "", "" }
... // methods
}
But when I do so, I got a error E309:
error[E0390]: cannot define inherent `impl` for primitive types
--> src/main.rs:50:6
|
50 | impl i32 {}
| ^^^
|
= help: consider using an extension trait instead
I am just wondering how core library do that? I think I follow the same syntax too.