summaryrefslogtreecommitdiff
path: root/meap/ch7.bak/src/main.rs
blob: 1dbb471b66afd698e314301e5ce7ef9f2186258f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//#[macro_use]
//extern crate serde_derive;
//
//extern crate serde;
//extern crate serde_json;
//extern crate bincode;
//
//#[derive(Serialize, Deserialize)]
//struct City {
//    name: String,
//    population: usize,
//    latitude: f64,
//    longitude: f64,
//}
//
//fn main() {
//    let calabar = City {
//        name: String::from("Calabar"),
//        population: 470_000,
//        latitude: 4.95,
//        longitude: 8.33,
//    };
//
//    let as_json = serde_json::to_string(&calabar).unwrap();
//    let as_bincode = bincode::serialize(&calabar).unwrap();
//
//    println!("json: {}", &as_json);
//    println!("bincode: {:?}", &as_bincode);
//    println!("bincode utf8: {:?}", String::from_utf8_lossy(&as_bincode));
//}


//use std::io::prelude::*;
//
//const BYTES_PER_LINE: usize = 16;
//const INPUT: &'static [u8] = br#"
//
//fn main() {
//    println!("hello world")
//}"#;
//
//fn main() -> std::io::Result<()> {
//    let mut buffer: Vec<u8> = vec!();
//    INPUT.read_to_end(&mut buffer)?;
//
//    let mut position_in_input = 0;
//    
//    for line in buffer.chunks(BYTES_PER_LINE) {
//        print!("[0x{:08x}] ", position_in_input);
//
//        for byte in line {
//            print!("{:02x} ", byte);
//        }
//
//        println!();
//        position_in_input += BYTES_PER_LINE;
//    }
//
//    Ok(())
//}


//use std::fs::File;
//use std::io::prelude::*;
//use std::env;
//
//const BYTES_PER_LINE: usize = 16;
//
//fn main() {
//    let arg1 = env::args().nth(1);
//    let fname = arg1.expect("usage: fview FILENAME");
//
//    let mut f = File::open(&fname).expect("unable to open file");
//    let mut pos = 0;
//    let mut buffer = [0; BYTES_PER_LINE];
//
//    while let Ok(_) = f.read_exact(&mut buffer) {
//        print!("[0x{:08x}] ", pos);
//        
//        for byte in &buffer {
//            match *byte {
//                0x00 => print!(".  "),
//                0xff => print!("## "),
//                _ => print!("{:02x} ", byte),
//            }
//        }
//
//        println!("");
//        pos += BYTES_PER_LINE;
//    }
//}


use std::path::PathBuf;

fn main() {
    let mut hello = PathBuf::from("/tmp/hello.txt");
    hello.pop();
    println!("{:?}", hello.display());
}