cornucopia-rs / cornucopia

Generate type-checked Rust from your PostgreSQL.
Other
755 stars 31 forks source link

Remove use of unsafe #234

Closed erikschul closed 5 months ago

erikschul commented 5 months ago

in private.rs

Ok(unsafe { self.cached.as_ref().unwrap_unchecked() })
LouisGariepy commented 5 months ago

@erikschul I'd be grateful if you could leave a small explanation for opening and closing this issue :)

I'm fairly certain the compiler would be able to optimize this without the need for unsafe since we actually check the option right above. And in any case the cost of unwrapping vanishes compared to the time it takes to handle the request. In other words, I'm open to consider this issue if needed.

erikschul commented 5 months ago

@LouisGariepy Ah, I discussed unsafe on Discord, and used this particular usage as an example, and their verdict was that it was "kosher" and that unsafe is fine. I still feel like it's better to avoid unsafe, but some people think it's fine. I'm not competent to judge it as an outright issue.

So that's why I closed it.