Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jonathan Dahan
committed
May 16, 2016
1 parent
1dc4976
commit 46ea228
Showing
1 changed file
with
38 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,40 @@ | ||
use std::env; | ||
use std::fs; | ||
use std::io::Read; | ||
|
||
fn main() { | ||
println!("Hello, world!"); | ||
let filename = env::args().nth(1).unwrap(); | ||
let mut file = fs::File::open(&filename).unwrap(); | ||
let mut buffer = Vec::new(); | ||
let _ = file.read_to_end(&mut buffer).unwrap(); | ||
|
||
println!("Opened {}, which is {} bytes", filename, buffer.len()); | ||
|
||
struct Range { | ||
offset: usize, | ||
length: usize | ||
}; | ||
|
||
struct Header { | ||
name: &'static str, | ||
range: Range | ||
}; | ||
|
||
let name_header = Header { | ||
name: "title", | ||
range: Range { | ||
offset: 308, | ||
length: 16 | ||
} | ||
}; | ||
|
||
let headers = vec![name_header]; | ||
|
||
for header in headers { | ||
let start = header.range.offset; | ||
let end = header.range.offset + header.range.length - 1; | ||
let mut header_slice = &buffer[start..end]; | ||
println!("{}: {}", header.name, String::from_utf8_lossy(&mut header_slice)); | ||
} | ||
|
||
} |