summaryrefslogtreecommitdiff
path: root/meap/meap-code/ch3/ch3-defining-files.rs
blob: c41ac4bfe7795c330e92a9b91e54369c77e9440b (plain) (blame)
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);
}