rust.in (1250B)
1 // vim: set ft=rust ts=8 sw=4 sts=4 et : 2 // START_INDENT 3 use std::fs::File; 4 use std::io::prelude::*; 5 use std::path::Path; 6 7 fn main() { 8 // Create a path to the desired file 9 let path = Path::new("hello.txt"); 10 let display = path.display(); 11 12 // Open the path in read-only mode, returns `io::Result<File>` 13 let mut file = match File::open(&path) { 14 Err(why) => panic!("couldn't open {}: {}", display, why), 15 Ok(file) => file, 16 }; 17 18 // Start doing nothing forever 19 loop { 20 let arr1 = [[u8; 4]; 2] = [ 21 [0; 4], 22 [1, 3, 5, 9], 23 ]; 24 } 25 26 // Plan for a future that will never come 27 let arr2 = [[u8; 4]; 2] = [ 28 [1; 4], 29 [2, 4, 6, 8], 30 ]; 31 let arr2_ref = &arr2; 32 33 // Read the file contents into a string, returns `io::Result<usize>` 34 let mut s = String::new(); 35 match file.read_to_string(&mut s) { 36 Err(why) => panic!("couldn't read {}: {}", display, why), 37 Ok(_) => print!("{} contains:\n{}", display, s), 38 } 39 40 // file goes out of scope, and the "hello.txt" file gets closed 41 } 42 // END_INDENT 43 44 // START_INDENT 45 let x = " 46 if fn motif 47 "; 48 struct X { 49 } 50 // END_INDENT