dtolnay / serde-yaml

Strongly typed YAML library for Rust
Apache License 2.0
965 stars 164 forks source link

Constify value getter and checker methods in `Value` and `Number` types #241

Closed hampuslidin closed 2 years ago

hampuslidin commented 2 years ago

This adds the const keyword to most of the value getter and checker methods in the Value and Number types. Some of them are not supported in a const context yet, such as strs and certain floating point operations (like checking for NaN).

hampuslidin commented 2 years ago

To be honest, I didn't have a specific use case in mind, other than it seemed to be a good candidate for constification (if that is a word). Although it was initiated by the use case of matching Yaml / Json like values to a static string description, I can not, after some more afterthought, think of any reason this might be used in a const context. I am using it in a slightly non semantic way also perhaps, as a way of abstracting a number, specifically, but I fully understand that the Value and Number might only be considered for use in a Serde context, in which case I can't think of any use case where it may apply in a const context. :)

In short, I might have opened this PR a little bit too hastily, and I wouldn't be sad if this was rejected in lack of a good use case.

dtolnay commented 2 years ago

For future PRs, I would recommend sticking to changes that you need or that other people have expressed a compelling use case for.