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
| // Copyright 2025 Google LLC
// SPDX-License-Identifier: Apache-2.0
#[derive(Debug)]
pub struct Date {
day: u8,
month: u8,
year: i64,
}
#[derive(Debug)]
pub struct User {
name: String,
date_of_birth: Date,
}
pub struct PlainTextPassword {
password: String,
hint: String,
}
impl std::fmt::Debug for PlainTextPassword {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("PlainTextPassword")
.field("hint", &self.hint)
.field("password", &"[omitted]")
.finish()
}
}
fn main() {
let user = User {
name: "Alice".to_string(),
date_of_birth: Date { day: 31, month: 10, year: 2002 },
};
println!("{user:?}");
println!(
"{:?}",
PlainTextPassword {
password: "Password123".to_string(),
hint: "Used it for years".to_string()
}
);
}
|