3 ms·
> it's not good Rust style to ignore return values, and dropping a type that should not be ignored If I remember correctly, much of OpenSSL is not written in "
by sdegutis 13y ago
> it's not good Rust style to ignore return values, and dropping a type that should not be ignored
If I remember correctly, much of OpenSSL is not written in "good C style" either. Considering that we're talking about "a language which is expected to have applications in safety/security-critical coding", it seems like a legitimate concern.
- pcwalton 13y agoI knew I would get someone calling me out on "it's not good Rust style". This style is enforced by warnings for important types, such as errors. The semicolon thing is repeatedly brought up as a possible source of errors, and I had concerns about it too at one point, but I've never seen it lead to a single one. There are just too many other safeguards. First of all, you get warnings on unused results for important types (for example, errors). Warning on dropping errors covers the hazards for crypto (and I can go into more detail here if wanted). Second, it's extremely unlikely that changing the return type from unit to something else won't cause a type error later down the line. For instance, returning a unit value from a function declared to return non-unit gives you a type error.
- kenko 13y ago> This style is enforced by warnings for important types, such as errors. How do you inform the compiler that a type is important? You might not be using the standard Result type.
- pcwalton 13y agoYou use an attribute, "#[must_use]". I haven't seen code not use the standard Result type, and I don't think it's likely. First of all, it's generic, so you aren't forced into a set of errors or an interface that you have to conform to—there's no reason not to use it. Second, there's strong pressure to use Result: all of the standard libraries use that type, so you'd have to write a lot of code to convert back and forth between your own error type and Result if you wanted to create your own for some reason. It'd also be less convenient from an import point of view: you'd always have to import your custom Result everywhere, whereas Result is always available right there in the prelude. Plus, you get really convenient "try!" macro sugar if you use Result. All of this means that you'd really have to go out of your way to not use Result, and my experience matches this.