Byte string vs u8 slice

Hi!

This seems to be not same:
1)

const SAVE_CURSOR: [u8;3] = [127, 91, 115]  is not b"\x1b[s"
const RESTORE_CURSOR: [u8;3] = [127, 91, 117] is not b"\x1b[u"

But
2)

const SAVE_CURSOR: [u8;3] = [127u8, 91u8, 115u8]  is the same like  b"\x1b[s"
const RESTORE_CURSOR: [u8;3] = [127u8, 91u8, 117u8] is the same like b"\x1b[u"

I find this confusing. Do I miss something?

When I use the 1) then I see [s and [u printed on the console.

Thanks, Paul

Would you mind providing a complete code example that produces different behavior for 1) and 2)?

Of course they are not the same, \x1b is 27, not 127. If you change that, they are the same.

If you see one of these behaving correctly but not the other, then you have the typo causing the extra 1 in one place but not in the other.

2 Likes

Thank H2CO3!

Sorry you are right. I didn't see that!

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.