if they have eggs, bring 6

error[E0277]: the trait bound `{integer}: Buy` is not satisfied
  --> src/main.rs:4:13
   |
2  |     buy(milk);
3  |     if they_have_eggs {
4  |         buy(6);
   |         --- ^ the trait `Buy` is not implemented for `{integer}`
   |         |
   |         required by a bound introduced by this call
   |
note: required by a bound in `buy`
  --> src/main.rs:11:22
   |
11 | fn buy(product: impl Buy) {
   |                      ^^^ required by this bound in `buy`

For more information about this error, try `rustc --explain E0277`.
error: could not compile `dad` (bin "errand") due to previous error
26 points · 4 comments · view on lemmy.world

4 Comments

Xanvial@lemmy.one · 4 pts · 3y (3 replies)

That's why you should use JS

dullbananas@lemmy.ca · 3 pts · 3y (2 replies)
fn main(){
    let mut input = std::io::stdin().lines();
    let num0 = input.next().unwrap().unwrap();
    let num1 = input.next().unwrap().unwrap();
    println!("{}", num0 + &num1);
}
Noodlez@programming.dev · 4 pts · 3y (1 reply)

Nothing makes me cringe more than seeing 4 unwraps in a row in Rust code. Like are you sure those errors will never happen? Do you really wanna panic?

And then I do it in my own code and I get it again. Rust error handling sucks ass. (I love Rust btw)

TALD@lemmy.fmhy.ml · 3 pts · 3y

I unwrap like a mad man while building a proof of concept. It's the same as approaching say a multithreaded program. You always get the single thread to work first and then worry about adding thread handling later.

Same as result and option handling, that's for when I want to stabilise my code before finalising for release.