Skip to content

Instantly share code, notes, and snippets.

View steveklabnik's full-sized avatar
🦀
Rustacean

Steve Klabnik steveklabnik

🦀
Rustacean
View GitHub Profile
@steveklabnik
steveklabnik / rust.md
Created June 8, 2014 02:03
Rust changes through versions

Originally taken from here, cached as a gist so I can find it later. "Angolmois" is a music video game, that plays real BeatMania files, so it's a pretty full-featured game. At least, as full as you're gonna find in Rust from as long ago as it was started.

Angolmois Rust edition went through six different Rust releases without almost no change on the features, and the changes are as follows:

@steveklabnik
steveklabnik / expanded.rs
Created June 20, 2014 22:01
an expanded hello
#![feature(phase)]
#![no_std]
#![feature(globs)]
#[phase(syntax, link)]
extern crate std = "std#0.11.0-pre";
extern crate native = "native#0.11.0-pre";
use std::prelude::*;
fn main() {
match (&2,) {
@steveklabnik
steveklabnik / number_game.md
Last active August 29, 2015 14:03
Rust first project

Help the docs!

EDIT: If you read the gist before, I've updated it with my latest version. I'm pretty sure I took care of everyone's comments, thanks so much!

So! The new tutorial will be focused on building several small projects in Rust. This example is the first one: a classic 'guessing game.' This was one of the first programs I wrote when I first learned C. 😄

I'd like the feedback of the community before I actually start writing the guide. So this code will be the final code of the first real example Rust programmers see. So I want it to be good. I don't claim this code is good, I just worked something out real quick. Oh, and this is tracking master.

The idea is that I will slowly build from hello world to this final code in steps, introducing one concept at a time. Here are the concepts I'd like a Rust programmer to understand by the time they're done:

match x {
x < 5 => ...,
x % 2 => ...,
}
let my_uuid = Uuid::parse_string("2665534263e644278f31ca69774af957").ok().expect("Parsing uuid failed");
let mut bdata = HashMap::new();
bdata.insert(Uuid::new_v4(), BlockDataString("Test".to_string()));
bdata.insert(Uuid::new_v4(), BlockDataInt(1337));
let my_block = Block{ id: my_uuid, data: box bdata };
log(&my_block);
use std::fmt::Show;
use std::fmt::Formatter;
use std::fmt::FormatError;
enum Tree<T> {
Node(T, Box<Tree<T>>, Box<Tree<T>>),
Nil,
}
impl<T: Ord + Show> Tree<T> {
cfg: build triple x86_64-unknown-linux-gnu
cfg: host triples x86_64-unknown-linux-gnu
cfg: target triples x86_64-unknown-linux-gnu
cfg: enabling more debugging (CFG_ENABLE_DEBUG)
cfg: host for x86_64-unknown-linux-gnu is x86_64
cfg: os for x86_64-unknown-linux-gnu is unknown-linux-gnu
cfg: using CC=ccache gcc (CFG_CC)
cfg: no llnextgen found, omitting grammar-verification
make: llvm
make[1]: Entering directory `/home/steve/src/rust/x86_64-unknown-linux-gnu/llvm'
cfg: build triple x86_64-unknown-linux-gnu
cfg: host triples x86_64-unknown-linux-gnu
cfg: target triples x86_64-unknown-linux-gnu
cfg: enabling more debugging (CFG_ENABLE_DEBUG)
cfg: host for x86_64-unknown-linux-gnu is x86_64
cfg: os for x86_64-unknown-linux-gnu is unknown-linux-gnu
cfg: using CC=ccache gcc (CFG_CC)
cfg: no llnextgen found, omitting grammar-verification
make: llvm
make[1]: Entering directory `/home/steve/src/rust/x86_64-unknown-linux-gnu/llvm'
cfg: build triple x86_64-unknown-linux-gnu
cfg: host triples x86_64-unknown-linux-gnu
cfg: target triples x86_64-unknown-linux-gnu
cfg: enabling more debugging (CFG_ENABLE_DEBUG)
cfg: host for x86_64-unknown-linux-gnu is x86_64
cfg: os for x86_64-unknown-linux-gnu is unknown-linux-gnu
cfg: using CC=ccache gcc (CFG_CC)
cfg: no llnextgen found, omitting grammar-verification
make -C /home/steve/src/rust/x86_64-unknown-linux-gnu/llvm ONLY_TOOLS="bugpoint llc llvm-ar llvm-as llvm-dis llvm-mc opt llvm-extract"
make[1]: Entering directory `/home/steve/src/rust/x86_64-unknown-linux-gnu/llvm'
#[no_mangle]
pub extern "C" fn hello_rust() {
println!("Hello, world!");
}