2024-08-11 11:31:05 +00:00
|
|
|
struct Notif {
|
|
|
|
app_name: String,
|
|
|
|
replace_id: u32,
|
|
|
|
ico: String, //It's string, right?
|
|
|
|
summary: String,
|
|
|
|
body: String,
|
|
|
|
//Actions
|
|
|
|
//Hints
|
|
|
|
expir_timeout: i32,
|
2024-08-10 21:29:13 +00:00
|
|
|
}
|
|
|
|
|
2024-08-11 11:31:05 +00:00
|
|
|
// Summary should be generally <= 40 chars, as per the specification.
|
|
|
|
fn truncate_summary(notif: &mut Notif) {
|
|
|
|
if notif.summary.len() > 40 {
|
|
|
|
notif.summary.truncate(39);
|
|
|
|
notif.summary.push_str("…");
|
2024-08-10 21:29:13 +00:00
|
|
|
}
|
2024-08-11 11:31:05 +00:00
|
|
|
}
|
2024-08-10 21:29:13 +00:00
|
|
|
|
2024-08-11 11:31:05 +00:00
|
|
|
fn main() {
|
|
|
|
let mut not = Notif {
|
|
|
|
app_name: "snot".to_string(),
|
|
|
|
replace_id: 0,
|
|
|
|
ico: "alert".to_string(),
|
|
|
|
summary: "This is a very long suuummmaaarrryyy! Don't you believe me????".to_string(),
|
|
|
|
body: "short body(hehe)".to_string(),
|
|
|
|
expir_timeout: 0
|
|
|
|
};
|
2024-08-11 11:32:35 +00:00
|
|
|
truncate_summary(&mut not); //Limit the summary length
|
2024-08-11 11:31:05 +00:00
|
|
|
|
|
|
|
println!("{}",not.summary);
|
2024-08-09 14:40:05 +00:00
|
|
|
}
|