test_repo

As usual, I test everything with cats
README | Files | Log | Refs

main.rs (592B)



struct FunktionaalinenKissa {
    command: String,
    action: fn(i32) -> i32,
}
// Meows
fn miau() -> &'static str {
    "meow meow"
}

fn jokin_funktio(n: i32) -> i32 {
    n*2
}
 
impl FunktionaalinenKissa {
    fn call(&self, n: i32) -> i32 {
        (self.action)(n)
    }
}

fn main() {
    let cmd = FunktionaalinenKissa {
        command: "moi".to_string(),
        action: jokin_funktio,
    };

    println!("Hello, {} world!", miau());
    println!("Hello, {} world times {}!", cmd.command, (cmd.action)(21));
    println!("Hello, {} world times {}!", cmd.command, cmd.call(2));
}