3 ms·
Taking a cursory look at their example, and this caught my eye: supervisor .broadcast("A message containing data.") .expect("Couldn't broadcast
by edvinbesic 4y ago
Taking a cursory look at their example, and this caught my eye:
supervisor
.broadcast("A message containing data.")
.expect("Couldn't broadcast the message.");
As a non-native English speaker, the word expect tricks me up here. Is this use correct?
- tmtvl 4y agoThat's standard Rust error-handling code: it prints an error message and panics out (if I remember correctly, I haven't touched Rust in years).
- 1letterunixname 4y ago"I found Rust when no one heard of them, man. They really knew how to put on a show back then. Now, they're so mainstream and commercial, I'm over 'em. Their latest album is so pop. I heard from their managers that brainfuck and Zig are touring this year." <- Hipsters on music ; @ D
- nequo 4y agoI think the recommendation is to phrase the error message that is given to .expect() not as what went wrong but as what we had expected to happen.[1] If the example that you show was consistent with that recommendation, it might look like this: supervisor .broadcast("A message containing data.") .expect("message broadcast should not fail"); Although even if you are a native English speaker, this is dubious improvement if you don’t know what Option types are and what .expect() does with them. [1] https://doc.rust-lang.org/std/option/enum.Option.html#recommended-message-style https://doc.rust-lang.org/std/option/enum.Option.html#recomm...
- 1letterunixname 4y agoexpect() is an assertion of non-failure. The string is the panic message on failure.