Skip to content

User's first example is complex #346

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

Closed
sophiajt opened this issue Nov 19, 2018 · 14 comments
Closed

User's first example is complex #346

sophiajt opened this issue Nov 19, 2018 · 14 comments
Assignees
Labels
A-Content The written content on the website.

Comments

@sophiajt
Copy link

Looking through the first example we show the users, I think it's great we get them comfortable with crates.io. That said, the code itself feels like the concept count may a be a bit on the high side for a first example:

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

fn main() {
    let stdout = stdout();
    let out = b"Hello fellow Rustaceans!";
    let width = 24;

    let mut writer = BufWriter::new(stdout.lock());
    say(out, width, &mut writer).unwrap();
}

Concepts covered:

  • External modules
  • Standard library
  • Byte strings (a user might wonder if all strings need a 'b' in front)
  • Locking generally, as well as locking of stdout (this seems peculiar to Rust and may surprise folks)
  • Mutable borrows (yay!)
  • Unwrapping (what does it mean to unwrap?)

If we want to keep the example largely the same, one possibility would be to allow the user to hover over parts of the code and get an explanation for each piece. This would let them have self-directed exploration of the unfamiliar parts.

@ashleygwilliams
Copy link
Member

the purpose of the code example is just for folks to cut and paste and get something working. we can work with the crate owner @mgattozi to improve the interface, but the aim is not to teach concepts but to teach the rust "workflow".

@ashleygwilliams ashleygwilliams added the A-Content The written content on the website. label Nov 20, 2018
@aturon aturon added this to the edition-release milestone Nov 29, 2018
@aturon
Copy link
Member

aturon commented Nov 29, 2018

I'm marking this to be resolved before the Edition. I will work with @mgattozi to simplify things a bit.

@Dagur
Copy link

Dagur commented Nov 29, 2018

The example didn't work for me. I had to add this line at the top

extern crate ferris_says;

@aturon aturon assigned ashleygwilliams and unassigned aturon Nov 30, 2018
@jzaefferer
Copy link

The example didn't work for me. I had to add this line at the top

extern crate ferris_says;

Maybe that's also part of the Rust workflow? 'If something goes wrong, do what the compiler tells you to fix it' 🥇

$ cargo run
   Compiling hello-rust v0.1.0 (/Users/joern.zaefferer/dev/other/hello-rust)
error[E0432]: unresolved import `ferris_says`
 --> src/main.rs:1:5
  |
1 | use ferris_says::say; // from the previous step
  |     ^^^^^^^^^^^ Maybe a missing `extern crate ferris_says;`?

error: aborting due to previous error

For more information about this error, try `rustc --explain E0432`.
error: Could not compile `hello-rust`.

To learn more, run the command again with --verbose.

@jzaefferer
Copy link

Or we need to switch the edition? There's a little bit about it here: https://rust-lang-nursery.github.io/cli-wg/tutorial/index.html

@steveklabnik
Copy link
Member

steveklabnik commented Dec 3, 2018 via email

@jzaefferer
Copy link

Gotcha. Since the current website advertises the beta site ('Try out the new beta site!'), this is a bit of a trap.

@ashleygwilliams ashleygwilliams modified the milestones: edition-release, end-of-year Dec 6, 2018
@Aloso
Copy link
Contributor

Aloso commented Dec 11, 2018

@ashleygwilliams I, too, think, that this code might confuse people who want to learn rust. Usually programmers don't like it, when they are told to execute a piece of code that they do not understand.

The code sample would be perfectly ok, if it was explained.

@yuxino
Copy link

yuxino commented Dec 17, 2018

Same issues for me , then i had to add extern crate ferris_says;.

@drumbsd
Copy link

drumbsd commented Jan 14, 2019

Same issue on OpenBSD 6.4. Fixed adding extern crate ferris_says; to solve.

@yoshuawuyts
Copy link
Member

@drumbsd the example is for the latest stable version of Rust with the edition = "2018" entry in Cargo.toml. This will be generated for you when running $ cargo init with the latest version of Rust installed.

You can update your Rust versions on Mac & Linux using the $ rustup update stable command (I'm not sure about Windows). Hope this is helpful!

@XAMPPRocky
Copy link
Member

I'm going to close this as #838 supersedes it.

@xgqfrms
Copy link

xgqfrms commented Dec 28, 2020

macOS still not work

// not fixed bug ❌
extern crate ferris_says;

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.as_bytes(), width, &mut writer).unwrap();
}

image

$ rustc --explain E0463

A plugin/crate was declared but cannot be found. Erroneous code example:

#![feature(plugin)]
#![plugin(cookie_monster)] // error: can't find crate for cookie_monster
extern crate cake_is_a_lie; // error: can't find crate for cake_is_a_lie


You need to link your code to the relevant crate in order to be able to use it
(through Cargo or the `-L` option of rustc example). Plugins are crates as
well, and you link to them the same way.


@Oosl
Copy link

Oosl commented Nov 16, 2021

@xgqfrms you must have to use cargo run to run your rust project, not rustc $FILE, when you created a rust project by cargo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Content The written content on the website.
Projects
None yet
Development

No branches or pull requests