piknik icon indicating copy to clipboard operation
piknik copied to clipboard

example builder fails at .body()

Open Xpyder opened this issue 3 years ago • 2 comments

Describe the bug I get a " the trait bound MaybeString: std::convert::From<&str> is not satisfied " when trying to use the example code. It's complaining when I try to use a plain string as the message body

To Reproduce

let email = Message::builder()
    .from("NoBody <[email protected]>".parse().unwrap())
    .reply_to("Yuin <[email protected]>".parse().unwrap())
    .to("Hei <[email protected]>".parse().unwrap())
    .subject("Happy new year")
    .body("Be happy!")
    .unwrap();

Expected behavior The provided example should work

Environment (please complete the following information):

  • Lettre version: "0.10.0-rc.4"
  • OS: Windows 10

Additional context Example pulled from: https://rustrepo.com/repo/lettre-lettre-rust-email

Error:

error[E0277]: the trait bound `MaybeString: std::convert::From<&str>` is not satisfied
  --> src\notification.rs:37:6
   |
37 |     .body("Be happy!")
   |      ^^^^ the trait `std::convert::From<&str>` is not implemented for `MaybeString`
   |
   = help: the following implementations were found:
             <MaybeString as std::convert::From<Vec<u8>>>
             <MaybeString as std::convert::From<std::string::String>>
   = note: required because of the requirements on the impl of `Into<MaybeString>` for `&str`
   = note: required because of the requirements on the impl of `IntoBody` for `&str`

Xpyder avatar Jan 05 '22 18:01 Xpyder

Services like crates.io, rustrepo ecc. usually show the readme from the most recent stable version, so in this case 0.9. body either expects a String or a Vec<u8> in 0.10, you're giving it a &str

paolobarbolini avatar Jan 05 '22 18:01 paolobarbolini

While you're not wrong, the Subject parameter does take an &str which makes the parameters inconsistent and confusing

Also given that the documentation says you can use a string this seems like it used to be supported, making this a breaking change in conflict with idiomatic rust which says to use &str instead of String whenever possible https://hermanradtke.com/2015/05/03/string-vs-str-in-rust-functions.html http://xion.io/post/code/rust-string-args.html

Is there a strong reason why body needs to be a String instead of accepting an &str?

Xpyder avatar Jan 05 '22 23:01 Xpyder