// テスト対象
fn publish_news(msg: &str, sender: &EmailSender, users: &[User]) -> u32 {
let mut count = 0;
let mut mail = Email {
from: "
[email protected]".to_string(),
to: "".to_string(),
msg: msg.to_string(),
};
for user in users {
mail.to = user.address.to_string();
match sender.send_mail(&mail) { // send_mail(&mail)をmockしたい
Ok(_) => count += 1,
Err(msg) => println!("Failed to send mail: {}", msg),
}
}
count
}
実装