This will not work
struct User {
active: bool,
username: String,
email: String,
sign_in_count: u64,
}
fn main() {
let user = User {
active: true,
username: String::from("someusername123"),
email: String::from("someone@example.com"),
sign_in_count: 1,
};
dbg!(user);
}
This will work
#[derive(Debug)]
struct User {
active: bool,
username: String,
email: String,
sign_in_count: u64,
}
fn main() {
let user = User {
active: true,
username: String::from("someusername123"),
email: String::from("someone@example.com"),
sign_in_count: 1,
};
dbg!(user);
}
Alternatively, you could fine tune it by replacing the #[derive(Debug)]
with the following:
impl fmt::Debug for User {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Point")
.field("active", &self.active)
.field("username", &self.username)
.field("email", &self.email)
.field("sign_in_count", &self.sign_in_count)
.finish()
}
}