1 // 99 characters, I guess I can’t add any more feature flags. Just as well I have all those I need.
2 #![feature(const_trait_impl, const_char_convert, const_option, const_fn_floating_point_arithmetic)]
4 // What do you want *docs* for!? (But I will begrudgingly allow doctests to run.)
5 #![cfg(any(not(doc), doctest))]
11 impl const Add
<u32> for U
{
14 fn add(self, n
: u32) -> char {
17 (n
/ 10) % 10 * 0x10 +
18 (n
/ 100) % 10 * 0x100 +
19 (n
/ 1000) % 10 * 0x1000 +
20 (n
/ 10000) % 10 * 0x10000 +
21 (n
/ 100000) % 10 * 0x100000
22 ).expect("I expected better of you. Depart, and reflect upon your transgressions.")
26 impl const Add
<f32> for U
{
29 fn add(self, f
: f32) -> char {
32 panic!("Begone, fractionaliser of U+ literals!");
37 (n
/ 10) % 10 * 0x10000 +
38 (n
/ 100) % 10 * 0x100000
39 ).expect("Will you never be better?")
43 impl const Add
<f64> for U
{
46 fn add(self, f
: f64) -> char {
49 panic!("Get ye hence, fracticious one!");
54 (n
/ 10) % 10 * 0x10000 +
55 (n
/ 100) % 10 * 0x100000
56 ).expect("I am exceedingly wrothful to youwards.")
62 assert_eq!(U
+0000, '
\u{0}'
);
63 assert_eq!(U
+1234, '
\u{1234}'
);
64 assert_eq!(U
+2f64, '
\u{2f64}'
);
65 assert_eq!(U
+102f64, '
\u{102f64}'
);
66 assert_eq!(U
+104f32, '
\u{104f32}'
);
67 // Evaluated at const time!
68 const MAX
: char = U
+109999;
69 assert_eq!(MAX
, '
\u{109999}'
);
73 /// #![feature(const_trait_impl)] // Not sure quite why this is needed, but meh.
75 /// const HAPPINESS: char = U+2323;
78 /// ```rust,compile_fail
79 /// #![feature(const_trait_impl)]
81 /// const MISERY: char = U+119999;
84 /// ```rust,compile_fail
85 /// #![feature(const_trait_impl)]
87 /// const SORROW: char = U+1F622;