I am using {:?} to print the value of a Breakfast struct. It includes the private field seasonal_fruit. Why I am able to print it with println!?
mod back_of_house {
#[derive(Debug)]
pub struct Breakfast {
pub toast: String,
seasonal_fruit: String, // NOT PUB !!!
}
impl Breakfast {
pub fn summer(toast: &str) -> Breakfast {
Breakfast {
toast: String::from(toast),
seasonal_fruit: String::from("Peaches"),
}
}
}
}
pub fn eat_at_restaurant() {
// Order a breakfast in the summer with Rye toast
let mut meal = back_of_house::Breakfast::summer("Rye");
// Change our mind about what bread we'd like
meal.toast = String::from("Wheat");
println!("I'd like {} toast please", meal.toast);
println!("I'd like {:?} toast please", meal);
}
fn main() {
eat_at_restaurant()
}