4 ms·
What libraries have you found to use unwrap liberally?
by faitswulff 4y ago
What libraries have you found to use unwrap liberally?
- davidatbu 4y ago_This_ is what I want to know.
- School-Cotton 4y agoThe standard library is one example. Indexing into a vector unwraps, as do many other stdlib functions.
- half-kh-hacker 4y agothe docs[0] are clear: > be careful: if you try to access an index which isn’t in the Vec, your software will panic! > Use get() and get_mut() if you want to check whether the index is in the Vec. In my experience, most people are using get() if the source of the index is untrusted [0]: https://doc.rust-lang.org/std/vec/struct.Vec.html#indexing https://doc.rust-lang.org/std/vec/struct.Vec.html#indexing
- spoiler 4y agoA lot of these Rust complaints are just people not reading the docs (not trying to say Rust doesn't have legitimate usage friction; of course it does). Pro tip: most popular crates have excellent documentation (I know it's a shocker coming from other languages). So, check stuff before you use it. I assume this is because the ecosystem lowers the barrier to entry for writing an generating documentation (compared to other ecosystems).
- School-Cotton 4y agoI wasn’t complaining about anything. I was simply giving an example of a library that behaves in this way.
- shakow 4y ago> Indexing into a vector unwraps That's what it's supposed to do, RTFM. Use .get() for safe access.
- School-Cotton 4y agoEr, yes I know, I use rust every day as a primary language. I was just giving an example, not claiming it wasn’t documented.
- shakow 4y agoThen what is the issue if you know both the “fast-but-panicking” and “slow-but-Option-ing” versions?
- School-Cotton 4y agoFirst of all, neither is faster than the other. Second, I never claimed it was an issue or a bad thing at any point. Someone asked for examples of libraries that panic, and I gave an example. I must be missing something because it makes no sense to me that people seem to be responding defensively and claiming that I either don’t understand the Rust docs or am pointing out problems in Rust.