ferrous-systems / rust-training

Learning materials for the Rust Training courses by Ferrous Systems
144 stars 19 forks source link

Should examples include fn main? #2

Closed jonathanpallant closed 1 year ago

jonathanpallant commented 1 year ago

This works in mdbook and mdslides:

let x = 6;

It will pass the tests. However, if you load it into the playground with the RUN button it won't work.

The playground requires you write it out in full:

fn main() {
    let x = 6;
}

Which is better?

amanjeev commented 1 year ago

I feel it is alright to include the full version if we want users to be able to run it. If we want only the first one, I would remove the Run button. I also do not want to hack any JS to add the fn main() part.

One other idea is to include a playground link at the bottom of each code snippet, and remove the Run button from code snippet. That way folks get a succinct code version with a link to playground to run it.

jonathanpallant commented 1 year ago

mdbook supports the idea of hiding lines of code by prefixing them with #, but I don't know how we'd teach highlight.js about this.

Maybe it's best to just make the examples fully runnable. Saves the trainer having to manually add the fn main() { and } after they've opened the playground.

amanjeev commented 1 year ago

I vote for full. two extra lines for runnable code yea i am ok with that.

jonathanpallant commented 1 year ago

Agreed