bson-rust icon indicating copy to clipboard operation
bson-rust copied to clipboard

RUST-1992 Introduce the `&CStr` and `CString` types for keys and regular expressions

Open abr-egn opened this issue 7 months ago • 0 comments

RUST-1992

This introduces the &CStr and CString types; these are zero-overhead equivalents to &str and String that witness that the text contain no zero bytes. These types are used to enforce that zero-byte checking is done for regular expressions and value keys at construction time (i.e. load or user input) rather than at encoding, which means (a) errors will happen closer to the root cause and (b) the encoding machinery can be simplified.

The new types are made fairly easy to work with via implementation of a swath of standard library traits and a cstr! macro that checks at compile-time if a given string literal is valid and errors with a friendly message if not.

abr-egn avatar Jun 27 '25 18:06 abr-egn