summaryrefslogtreecommitdiff
path: root/meap/meap-code/ch1/ch1-save-user-data.rs
blob: 48f8130d802eda5ceac15df35f99174fc7ba5bd6 (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
use std::str;

#[derive(Debug)]
struct User {
    id: u8,
    secret: String,
}

fn store_secrets(user: &User, buffer: &mut[u8]) {
    let _secret = user.secret.clone();

    
    // assume we're writing to a database
    println!("{:?}: {}", user, str::from_utf8(&buffer).unwrap());
}

fn main() {
    let buffer = &mut[0u8; 1024];
    let u1 = User {
        id: 1,
        secret: String::from("Pa55w0rd!"),
    };
    let u2 = User {
        id: 2,
        secret: String::from("correct horse battery staple"),
    };

    store_secrets(&u1, buffer);
    store_secrets(&u2, buffer);
    

}