Skip to content

ex4 #81020

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tariqjamil-bwp opened this issue Jan 14, 2021 · 0 comments
Closed

ex4 #81020

tariqjamil-bwp opened this issue Jan 14, 2021 · 0 comments

Comments

@tariqjamil-bwp
Copy link

fn main() {
    let string1 = String::from("abcd");
    let string2 = "xyz";
    
    let result = longest_with_announcement (
    string1.as_str(),
    string2,
    "Today is someones' birthday !",
    );
    
    println!("The longest string is {}", result);
}

use std::fmt::Display;

fn longest_with_announcement<'a, T> (
    x: &'a str,
    y: &'a str,
    ann: T,
) -> &'a str
where 
    T:Display,
{
    println!("Announcement! {}", ann);
    if x.len() > y.len() {
        x
    } else {
        y
    }
}

(Playground)

Output:

Announcement! Today is someones' birthday !
The longest string is abcd

Errors:

   Compiling playground v0.0.1 (/playground)
    Finished dev [unoptimized + debuginfo] target(s) in 1.85s
     Running `target/debug/playground`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants