This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::sync::atomics::AtomicBool; | |
| use std::sync::atomics::Ordering; | |
| // error unresolved import: there is no `Relaxed` in `std::sync::atomics::Ordering` | |
| // use std::sync::atomics::Ordering::Relaxed; | |
| fn main() { | |
| let mut ab = AtomicBool::new(false); | |
| let val1 = ab.load(Ordering::Relaxed); // error: unresolved import: | |
| // there is no `Relaxed` in `std::sync::atomics::Ordering` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "runtime" | |
| ) | |
| func whisper(left, right chan int) { | |
| left <- 1 + <- right | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::io::File; | |
| use std::str; | |
| fn main() { | |
| let file_name_abs = ~"foo"; | |
| let mut response =~ ""; | |
| match File::open(&Path::new(file_name_abs)) { | |
| Some(html_file) => { | |
| let mut html_file_mut = html_file; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fn double(a: int) -> int { a * 2 } | |
| fn ntimes(f: proc(int) -> int, times: int) -> proc(int) -> int { | |
| proc(x: int) { | |
| match times { | |
| 0 => { x }, | |
| _ => { f(ntimes(f, times - 1)(x)) } // swap the order relative to the original example | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| My measurements for the "kernel interrupt timing" programs: | |
| |--------------------+-----------------+-------------+------------------------------| | |
| | SIGALRM Interval | Program version | Measured Hz | Measured Interval Avg (usec) | | |
| |--------------------+-----------------+-------------+------------------------------| | |
| | (init setting) 250 | Rust | 4001 | 250 | | |
| | (init setting) 250 | C | 4016 | 249 | | |
| |--------------------+-----------------+-------------+------------------------------| | |
| | 500 | Rust | 2001 | 500 | | |
| | 500 | C | 2004 | 499 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::io::process; | |
| use std::io::process::{Process, ProcessConfig}; | |
| use std::comm::{Port, Chan}; | |
| fn main() { | |
| let (port, chan) = Chan::new(); | |
| spawn(proc(){taskEntry(port)}); | |
| chan.send(~"ls"); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::io::EndOfFile; | |
| use std::io::io_error; | |
| // ... | |
| fn respond_with_static_file(stream: Option<std::io::net::tcp::TcpStream>, path: &Path) { | |
| let mut stream = stream; | |
| let sz = 16384; | |
| let result = io::result(|| File::open(path)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct MyThing { | |
| val: int | |
| } | |
| impl MyThing { | |
| fn remove_first(s: &str) -> ~str { | |
| s.slice_from(1).to_owned() | |
| } | |
| fn remove_last(&self, s: &str) -> ~str { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Rust code | |
| use std::libc; | |
| use std::ptr; | |
| struct memcached_st; | |
| struct memcached_server_st; | |
| struct memcached_server_list_st; | |
| type in_port_t = i32; | |
| #[repr(C)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::str::StrVector; | |
| struct A<'a> { | |
| field: &'a StrVector | |
| } | |
| fn main() { | |
| let vs = ~[~"one", ~"two", ~"three"]; | |
| let cc = vs.concat(); | |
| println!("{:?}", cc); // works |