konst/
chr.rs

1//! Const equivalents of `char` functions.
2//!
3//! The module is called `chr` to avoid name collisions with the `char` type.
4
5/// A char encoded as a utf8 string.
6///
7/// # Example
8///
9/// ```rust
10/// use konst::chr;
11///
12/// const ENC: &chr::Utf8Encoded = &chr::encode_utf8('û');
13/// const ENC_STR: &str = ENC.as_str();
14///
15/// assert_eq!(ENC_STR, "û");
16///
17/// ```
18pub use konst_kernel::chr::Utf8Encoded;
19
20/// Encodes `c` into utf8, const analog of [`char::encode_utf8`].
21///
22/// # Const stabilization
23///
24/// The equivalent std function was const-stabilized in Rust 1.83.0.
25///
26/// # Example
27///
28/// ```rust
29/// use konst::chr;
30///
31/// const ENC: &chr::Utf8Encoded = &chr::encode_utf8('🤔');
32/// const ENC_STR: &str = ENC.as_str();
33///
34/// assert_eq!(ENC_STR, "🤔");
35///
36/// ```
37pub use konst_kernel::chr::encode_utf8;
38
39/// Unsafely coerces `u32` to `char`,
40/// const equivalent of [`char::from_u32_unchecked`]
41///
42/// # Const stabilization
43///
44/// The equivalent std function was const-stabilized in Rust 1.82.0.
45///
46/// # Safety
47///
48/// The input `u32` must be within either of these ranges:
49///
50/// - `0..=0xD7FF`
51/// - `0xE000..=0x10FFFF`
52///
53/// # Example
54///
55/// ```rust
56/// use konst::chr;
57///
58/// const AT: char = unsafe { chr::from_u32_unchecked(64) };
59///
60/// assert_eq!(AT, '@');
61/// ```
62pub use konst_kernel::chr::from_u32_unchecked;
63
64/// Fallible conversion from `u32` to `char`,
65/// const equivalent of [`char::from_u32`]
66///
67/// # Const stabilization
68///
69/// The equivalent std function was const-stabilized in Rust 1.67.0.
70///
71/// # Example
72///
73/// ```rust
74/// use konst::{chr, option};
75///
76/// const AT: char = option::unwrap!(chr::from_u32(64));
77///
78/// assert_eq!(AT, '@');
79/// ```
80pub use konst_kernel::chr::from_u32;