trait Greet {
    fn greet(&self) -> String;
}

struct English;
struct Japanese;

impl Greet for English {
    fn greet(&self) -> String {
        "Hello!".to_string()
    }
}

impl Greet for Japanese {
    fn greet(&self) -> String {
        "こんにちは!".to_string()
    }
}

// Traitを戻り値とする関数（dynトレイトのBoxで返す）
fn create_greeter(lang: &str) -> Box<dyn Greet> {
    match lang {
        "en" => Box::new(English),
        "ja" => Box::new(Japanese),
        _ => Box::new(English),
    }
}

fn main() {
    let greeter = create_greeter("ja");
    println!("{}", greeter.greet());

    let greeter = create_greeter("en");
    println!("{}", greeter.greet());
}