We follow the Rust Code of Conduct (www.rust-lang.org/en-US/conduct.html)
In case of problem, feel free to contact either me or Karsten in person or via mail/twitter
@crepererum
type buf_writer = obj {
fn write(vec[u8] buf) -> uint;
};
fn read(vec[u8] v) -> uint {
auto len = _vec.len[u8](v);
auto buf = _vec.buf[u8](v);
auto count = os.libc.read(fd, buf, len);
if (count < 0) {
log "error filling buffer";
log sys.rustrt.last_os_error();
fail;
} else {
ret uint(count);
}
}
drop {
os.libc.close(fd);
}
alt, any, as, auth, auto, be, bind, bool, case, chan,
char, check, claim, do, drop, each, else, export, f32,
f64, fail, false, fn, for, i16, i32, i64, i8, if,
import, in, int, io, iter, join, let, log, meta, mod,
mutable, native, obj, port, prove, put, rec, ret,
spawn, state, str, syntax, tag, task, thread, true, tup,
type, u16, u32, u64, u8, uint, unsafe, use, vec, while,
with, yield
# struct Point {x: float, y: float}
let on_the_stack : Point = Point {x: 3.0, y: 4.0};
let shared_box : @Point = @Point {x: 5.0, y: 1.0};
let unique_box : ~Point = ~Point {x: 7.0, y: 9.0};
fn read_username_from_file() -> Result<String, io::Error> {
let mut f = File::open("username.txt")?;
let mut s = String::new();
f.read_to_string(&mut s)?;
Ok(s)
}
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
#[derive(Serialize, Deserialize, Debug)]
struct Pet {
name: String,
}
fn main() {
let pet = Pet { name: String::from("Ferris") };
let serialized = serde_json::to_string(&pet).unwrap();
println!("serialized = {}", serialized);
let deserialized: Pet = serde_json::from_str(&serialized).unwrap();
println!("deserialized = {:?}", deserialized);
}
#[derive(Queryable)]
struct Pet {
name: String,
}
fn main() {
use diesel_demo::schema::pets::dsl::*;
let connection = establish_connection();
let results = pets
.limit(5)
.load::<Pet>(&connection)
.expect("Error loading pets");
println!("Displaying {} pets", results.len());
for pet in results {
println!("{}", pet.name);
}
}
union MyUnion {
f1: u32,
f2: f32,
}
let u = MyUnion { f1: 1 };
unsafe { u.f1 = 5 };
let value = unsafe { u.f1 };
// old code
let x;
loop {
x = 7;
break;
}
// new code
let x = loop { break 7; };
struct Struct;
impl Struct {
const ID: u32 = 0;
}
fn main() {
println!("the ID of Struct is: {}", Struct::ID);
}
// before
fn foo() -> Box<Fn(i32) -> i32> {
Box::new(|x| x + 1)
}
// after
fn foo() -> impl Fn(i32) -> i32 {
|x| x + 1
}
#[route(GET, "/")]
fn index() {
// ...
}
let sql = sql!(SELECT * FROM posts WHERE id=1);
const fn foo(x: i32) -> i32 {
x + 1
}
fn main() {
let mut x = 5;
let y = &x;
let z = &mut x;
}
Any editor + terminal
Visual Studio Code (Rust + CodeLLDB + TOML + Crates)
More at areweideyet.com
Rust Playground (play.rust-lang.org)
Evcxr + Binder (goo.gl/AHsKxe)
Locally or via Rust Playground
Nice large collections, requires special CLI client
Locally
Different Crates
Rust Itself
at Mytaxi
January, 24th
You Talk?