lucab / libsystemd-rs

A pure-Rust client library to work with systemd
https://crates.io/crates/libsystemd
Other
105 stars 19 forks source link

Forgo validation of MESSAGE and PRIORITY fields at runtime #131

Closed dfreese closed 1 year ago

dfreese commented 1 year ago

This changes where the validation of the field happens to so that the validity of MESSAGE and PRIORITY can be asserted during tests, rather than in each run of add_field_and_payload.

To make this a little more explicit, this changes introduces ValidField as a helper struct for the interface on add_field_and_payload. ValidField is constructed primarily by calling it's validate function, which returns None if the field is invalid. It also has an unchecked function that effectively breaks this guarantee, under the assumption that validate_unchecked will be called during tests. This pair allows for ValidField to be const.

swsnr commented 1 year ago

Nice idea!