summaryrefslogblamecommitdiff
path: root/meap/meap-code/ch3/ch3-mock-file.rs
blob: a07645ce923a20e0f5b6fa955ef34adfc67e9ccd (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

















                                                      
#[derive(Debug)] // <1>
struct File {
  name: String,
  data: Vec<u8>, // <2>
}

fn main() {
  let f1 = File { 
    name: String::from("f1.txt"), // <3>
    data: Vec::new(), // <4>
  };
  
  let f1_name = &f1.name; // <5>
  let f1_length = &f1.data.len(); // <5>
  
  println!("{:?}", f1);
  println!("{} is {} bytes long", f1_name, f1_length);
}