core/primitive.rs
1//! This module reexports the primitive types to allow usage that is not
2//! possibly shadowed by other declared types.
3//!
4//! This is normally only useful in macro generated code.
5//!
6//! An example of this is when generating a new struct and an impl for it:
7//!
8//! ```rust,compile_fail
9//! pub struct bool;
10//!
11//! impl QueryId for bool {
12//! const SOME_PROPERTY: bool = true;
13//! }
14//!
15//! # trait QueryId { const SOME_PROPERTY: ::core::primitive::bool; }
16//! ```
17//!
18//! Note that the `SOME_PROPERTY` associated constant would not compile, as its
19//! type `bool` refers to the struct, rather than to the primitive bool type.
20//!
21//! A correct implementation could look like:
22//!
23//! ```rust
24//! # #[allow(non_camel_case_types)]
25//! pub struct bool;
26//!
27//! impl QueryId for bool {
28//! const SOME_PROPERTY: ::core::primitive::bool = true;
29//! }
30//!
31//! # trait QueryId { const SOME_PROPERTY: ::core::primitive::bool; }
32//! ```
33//!
34//! We also used `::core` instead of `core`, because `core` can be
35//! shadowed, too. Paths, starting with `::`, are searched in
36//! the [extern prelude] since Edition 2018.
37//!
38//! [extern prelude]: https://doc.rust-lang.org/nightly/reference/names/preludes.html#extern-prelude
39
40#[stable(feature = "core_primitive", since = "1.43.0")]
41pub use bool;
42#[stable(feature = "core_primitive", since = "1.43.0")]
43pub use char;
44#[stable(feature = "core_primitive", since = "1.43.0")]
45pub use f32;
46#[stable(feature = "core_primitive", since = "1.43.0")]
47pub use f64;
48#[stable(feature = "core_primitive", since = "1.43.0")]
49pub use i8;
50#[stable(feature = "core_primitive", since = "1.43.0")]
51pub use i16;
52#[stable(feature = "core_primitive", since = "1.43.0")]
53pub use i32;
54#[stable(feature = "core_primitive", since = "1.43.0")]
55pub use i64;
56#[stable(feature = "core_primitive", since = "1.43.0")]
57pub use i128;
58#[stable(feature = "core_primitive", since = "1.43.0")]
59pub use isize;
60#[stable(feature = "core_primitive", since = "1.43.0")]
61pub use str;
62#[stable(feature = "core_primitive", since = "1.43.0")]
63pub use u8;
64#[stable(feature = "core_primitive", since = "1.43.0")]
65pub use u16;
66#[stable(feature = "core_primitive", since = "1.43.0")]
67pub use u32;
68#[stable(feature = "core_primitive", since = "1.43.0")]
69pub use u64;
70#[stable(feature = "core_primitive", since = "1.43.0")]
71pub use u128;
72#[stable(feature = "core_primitive", since = "1.43.0")]
73pub use usize;