Amanieu / cstr_core

Implementation of CStr and CString for no_std environments
Apache License 2.0
41 stars 17 forks source link

How to get the length of a `CStr`? #20

Open wucke13 opened 3 years ago

wucke13 commented 3 years ago

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

Amanieu commented 3 years ago

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

chrysn commented 2 years ago

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.