cstr_core icon indicating copy to clipboard operation
cstr_core copied to clipboard

How to get the length of a `CStr`?

Open wucke13 opened this issue 4 years ago • 2 comments

I would love to see some .len() functions in all the type of this crate.

wucke13 avatar Feb 23 '21 13:02 wucke13

You can use .to_bytes().len().

Amanieu avatar Feb 23 '21 13:02 Amanieu

Agreeing with @Amanieu. "length" has two distinct meanings here (length with and length without the nul), so it's better to explicitly indicate which length to get either by using .to_bytes() or .to_bytes_with_nul() when asking length.

chrysn avatar Dec 20 '21 12:12 chrysn