Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there syntax for declaring character literals in hexadecimal notation?

Something like

const X: char = '0x10FFFC';
like image 893
alagris Avatar asked Oct 15 '25 15:10

alagris


1 Answers

Yes, use \u{..}:

const X: char = '\u{10FFFC}';

Playground

One trick for this cases is play with the compiler. If you try the following code it will give you a nice hint about what to do for example:

const X: char = 0x10FFFC as char;
error: only `u8` can be cast into `char`
 --> src/lib.rs:1:17
  |
1 | const X: char = 0x10FFFC as char;
  |                 ^^^^^^^^^^^^^^^^ help: use a `char` literal instead: `'\u{10FFFC}'`
  |
  = note: `#[deny(overflowing_literals)]` on by default
like image 62
Netwave Avatar answered Oct 18 '25 07:10

Netwave



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!