use std::{result, fmt::Display};
struct ImportantExcerpt<'a>{
part: &'a str,
}
impl<'a> ImportantExcerpt<'a>{
fn announce_and_return_part(&self, announcement: &str) -> &str{
println!("Attention please: {}", announcement);
self.part }
}
pub fn main(){
let string1 = String::from("abcd");
let string2 = String::from("xyz");
let res = longest(string1.as_str(), string2.as_str());
println!("The longest string is: {}", res);
let novel = String::from("Call me Revv. Some days ago...");
let first_sentence = novel.split('.').next().expect("Could not find a sentence");
let i = ImportantExcerpt{
part: first_sentence
};
}
fn longest<'a>(x: &'a str, y: &'a str) -> &'a str{ if x.len() > y.len(){
x
} else {
y
}
}
fn longest_with_announcement<'a, T>(x: &'a str, y: &'a str, announce: T) -> &'a str where T:Display{
println!("Announcement! {}", announce);
if x.len() > y.len(){
x
} else {
y
}
}