Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong example code which doesn't compile #1847

Closed
Xuanmizhen opened this issue Jul 24, 2023 · 2 comments · Fixed by #1848
Closed

Wrong example code which doesn't compile #1847

Xuanmizhen opened this issue Jul 24, 2023 · 2 comments · Fixed by #1848
Labels
A-Design UI / UX of the website. C-Bug Something isn't working.

Comments

@Xuanmizhen
Copy link

Page(s) Affected

https://www.rust-lang.org/learn/get-started
https://www.rust-lang.org/zh-CN/learn/get-started
https://www.rust-lang.org/zh-TW/learn/get-started
etc. (in other languages)

What needs to be fixed?

In the referred pages, the example code below the title A small Rust application DOESN'T compile.

error[E0308]: mismatched types
  --> src/main.rs:10:9
   |
10 |     say(message.as_bytes(), width, &mut writer).unwrap();
   |     --- ^^^^^^^^^^^^^^^^^^ expected `&str`, found `&[u8]`
   |     |
   |     arguments to this function are incorrect
   |
   = note: expected reference `&str`
              found reference `&[u8]`
note: function defined here
  --> /Users/username/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ferris-says-0.3.1/src/lib.rs:84:8
   |
84 | pub fn say<W>(input: &str, max_width: usize, mut writer: W) -> Result<()>
   |        ^^^

For more information about this error, try `rustc --explain E0308`.
error: could not compile `rust-journey` (bin "rust-journey") due to previous error

Suggested Improvement

Fix the code with the following:

use ferris_says::say; // from the previous step
use std::io::{stdout, BufWriter};

fn main() {
    let stdout = stdout();
    let message = String::from("Hello fellow Rustaceans!");
    let width = message.chars().count();

    let mut writer = BufWriter::new(stdout.lock());
    say(&message, width, &mut writer).unwrap();        // Change only this line
}
@Xuanmizhen Xuanmizhen added A-Design UI / UX of the website. C-Bug Something isn't working. labels Jul 24, 2023
@Xuanmizhen
Copy link
Author

I've checked the version of ferris-says on my computer, and found that the version is 0.3.1, while the version mentioned on the website is 0.2.

@Manishearth
Copy link
Member

Yes, the example on the website uses an older ferris-says, which it asks you to add as a dependency.

We should update both, though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Design UI / UX of the website. C-Bug Something isn't working.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants