Traits Example 1

use std::fmt::Display;

trait Double {

    fn double(self) -> String;
}

impl Double for &str {
    
    fn double(self) -> String {
    
        let mut owned: String = self.to_owned().to_string();
    
        owned.push_str(self);
    
        owned
    }
}


// Trait as parameter

fn print_double(v: impl Double+Display) {

    println!("Here is a double {}: ", v.double());
}

fn main() {
    
    println!("{}", "Ciao ".double());
    
    print_double("Ciao ");
}