How to convert char to u8?

I'm trying to build my own custom json encoder. Where I'm planning to reuse to bytes.
Basically, I'm trying to do something like this

let a: Vec<u8> = Vec::new();
a.push('{');
....

You can't always do that, some chars are out of a u8's range.
Note that if you're just dealing with u8's, you can prepend a b to the character:

a.push(b'{'):
2 Likes

JSON is defined as “a sequence of Unicode codepoints” (cf §2), so using Vec<char> or String to collect the encoded value is perhaps more appropriate than Vec<u8>, as they are both designed to handle the full range of Unicode.

2 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.