Soliciting multiple new examples for homepage

Yehuda's work for fast_blank in rust is one of my favorite examples for zero cost abstractions + C FFI. @steveklabnik has a nice tldr on reddit. It's also about 100x shorter than the matching C implementation.

There's an error. Your solidus invokes the multiplly operation instead of the division one.

No it doesn't, don't be ridiculous. cough

I like their site too, though it's focus is a lot different from ours. I like that they have small examples, paired with explanations. I don't love that there's so much text visible by default.

I see ours primarily directing you to how to install then how to find more information. Assuming people know Rust by reputation and don't need to be sold again, but giving you a quick hint that you are in the right place, get you excited, then links to more info. I want to preserve our minimalism (on this page at least).

What I'd like to see is several small examples, that we can (when JS exists) display one at a time. Possibly each paired with a one-sentence description and a link to more information.

On the subject of Cargo, I'd like to be able to show and run Cargo examples. Play can be fixed to support it perhaps. I don't want to explain Cargo.toml on the Rust home page. Having to explain that the example doesn't work without pairing it with another file, and one that is not interesting or relevant to demonstrate the beauty of the Rust language, is extremely undesirable to me. Cargo should have a subcommand or plugin that will figure out what crates you want from the source so we can say 'Run this as locally with cargo blah'.

cc @Lurkin about play not dealing with Cargo

Edit: cargo-script does something close to what I'd expect for demoing simple cargo-ified source. The only annotation in requires is // cargo-deps.

cargo-script bundles together fetching, building and execution, which may or may not be an issue with the playpen. Just FYI: you can use --gen-pkg-only to have it "extract" the source file into a regular Cargo package. If that's too heavy-weight, I could also always just spin the relevant code into an external crate.

There might be some nice examples on GitHub - rust-rosetta/rust-rosetta: Implementing Rosetta Code problems in Rust. if anyone needs ideas.

1 Like

Discussing with Lurkin on irc, the current plan for external crates on playpen is basically a whitelist. So it should be pretty easy to just drop the whitelisted crates in cargo's cache, configure it to have a bogus index URL, and call it a day.

Here's a "doesn't compile, thank goodness" example:

fn append_slice<T: Copy>(v: &mut Vec<T>, s: &[T])
    for &t in s { v.push(t); }

fn main() {
    let mut v = vec![1,2,3];
    let w = vec![4,5,6];
    append_slice(&mut v, &w[..]); // This is okay.
    assert_eq!(v, [1,2,3,4,5,6]);
    // This doesn't compile, and that's a good thing:
    // what if we reallocated v's buffer mid-append?
    // s would be pointing at freed memory!
    append_slice(&mut v, &v[..]);

Here is a Gist containing various examples. I tried to get at least one for each "bullet point" feature on the front page. All of them fit within the existing 69×22 cell space (which was a bastard to do, let me tell you).

The only one that requires a Cargo dep is that shows mutating an array on the stack with multiple threads. That (and all the others, incidentally) can be run directly with cargo script.


Do we guarantee left-to-right evaluation order?

I can understand the idea of replacing that packed code with some more simple examples. But I've to say something against it, it probably won't change anything, as I can see both sides, anyway:

The part that gave me the kick, to learn rust, after reading all the stuff like guaranteed memory safety, was exactly this, stuffed, code.
Why ?
Because it showed, that rust is able to work with things like strings & patterns as a low-level lang without much extra work. It also showed how easy it's to directly print the result, in a formatted, good way.
It was the thing that hit me.

Of course you can also show this by dividing it into multiple examples, but for the "fast reader", like I can be one, it was the best introduction.


Please add more examples which are friendlier to new users

  1. after hello world and data types

    use std::io;
    fn main() {
        let mut user_input = String::new();
        io::stdin().read_line(&mut user_input)
            .expect("Failed to read line!");
        println!("Hello, World.\n{}", user_input);
  2. after structs and trails

    struct Player {
        first_name: String,
        last_name: String,
    impl Player {
        fn new(first_name: String, last_name: String) -> Player {
            Player {
                first_name : first_name,
                last_name : last_name,
        fn full_name(&self) -> String {
            format!("{} {}", self.first_name, self.last_name)
    fn main() {
        let player_name = Player::new("Serena".to_string(), "Williams".to_string()).full_name();
        println!("Player: {}", player_name);

and etc. Also please order docs properly, new users learn about borrow and checker before basics of structs, vectors and etc. This will confuse the absolute new comers.

I think that goal is served by the "more examples" link, to me the goal of the example visible directly at the home page is to show the power of Rust, or "why should I bother with this language" if you will, but the OO model of Rust is sufficiently unfamiliar to C++/Java programmers that I agree it is worth showing up front, if we have multiple examples.

I disagree here, it is important to know the absolute basics of the language to be able to know how and where the borrow checker applies, in other words if you don't even know how to declare bindings, structs etc. there's no point in showing you ownership, since the concept is demonstrable only using such constructs.

Also, the concept that you cannot do anything in Rust without understanding the borrow checker is misleading and may drive more users away, if the first thing they're hit with is this 'intimidating' concept of ownership and borrowing, if you will.

This might not be the right place or the right time, but I would like to suggest a new layout for Rust main page.

  1. Top:
    Rust Logo and links for menu items (doc, forum, download, contribute/help, hamburger icon for other menu items)

  2. Next
    Special graphs(random/list with link under the graph for more details) and intro (Rust is a systems programming language that runs blazingly fast, prevents segfaults, and guarantees thread safety.)
    Graphs ex Rust - Rethinking Systems Programming, graphs in My experience rewriting Enjarify in Rust | by Robert Grosse | Medium etc

  3. Examples
    Feature list, on click right side code/video getting changed.

  4. Crates and areas uses Rust
    short intro to crates, side crate downloads count & crate count
    Links with/without images for pages like xi editor, hyper, nickel, Piston, arewewebyet and etc.

  5. Users/ Friends of Rust

  6. bottom
    links for fb, youtube, twitter, github, stackoverflow, blog and etc.