View asdf.cpp
#include <iostream>
#include <vector>
int main() {
std::vector<int> v { 2, 3, 4 };
for(auto i: v) {
if (i % 2 == 0) {
v.push_back(i * -1);
}
}
View sprite.rs
src\scene.rs:54:30: 54:34 error: cannot borrow `*self` as mutable more than once at a time
src\scene.rs:54 let sprite = self.child_mut(id).unwrap();
^~~~
src\scene.rs:54:30: 54:34 note: previous borrow of `*self` occurs here; the mutable borrow prevents subsequent moves, borrows, or modification of `*self
` until the borrow ends
src\scene.rs:54 let sprite = self.child_mut(id).unwrap();
^~~~
src\scene.rs:81:6: 81:6 note: previous borrow ends here
src\scene.rs:40 pub fn event<E>(&'a mut self, e: &E) where E: GenericEvent {
...
View z.rs
extern crate serde;
use std::env;
use std::path::Path;
use serde::json;
fn main() {
let our_args: Vec<String> = std::env::args().collect();
let base_name = Path::new(&our_args[0])
.file_name().expect("Path is not a file")
View argg.rs
use std::io::BufRead;
fn main() {
let stdin = std::io::stdin();
for line in stdin.lock().lines().take(2) {
println!("{}", line.unwrap());
}
}
View asclosure.rs
fn main() {
let make_counter = || {
let mut count = 0;
move || { let so_far = count; count += 1; so_far }
};
let mut a = make_counter();
let mut b = make_counter();
println!("{} {}", a(), a());
println!("{} {}", b(), b());
}
View Cargo.toml
[package]
name="bob"
version="0.0.1"
authors=["insaneinside"]
[lib]
name="bob"
path="lib.rs"
View Cargo.toml
[package]
name="bob"
version="0.0.1"
[lib]
name="bob"
path="lib.rs"
View arity.txt
Tremendously hacky measurement of the arity of function signatures in the Rust repository:
0 12919 48.10%
1 7703 28.68%
2 3388 12.61%
3 1544 5.74%
4 705 2.62%
5 345 1.28%
6 144 0.53%
7 58 0.21%
View Comparison Problem
#[deriving(PartialEq)]
enum Ordering {
Less,
Equal,
Greater,
}
fn cmp(a: int, b: int) -> Ordering {
if a < b { Less }
else if a > b { Greater }
View area.rs
trait HasArea {
fn area(&self) -> f64;
}
trait RectangularArea: HasArea {
fn area(&self) -> f64 {
self.length() * self.width()
}
fn length(&self) -> f64;
fn width(&self) -> f64;