Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR RUST

optional arguments rust

fn hello(message: Option<&str>) -> String {
    match message {
        Option::Some(_) => message.unwrap().to_owned(),
        Option::None => String::from("Hello World")
    }
}

macro_rules! hello {
    ($message: expr) => {
        println!("{}", hello(Option::Some($message)))
    };
    () => {
        println!("{}", hello(Option::None))
    }
}

fn main() {
    hello!("Hello"); // prints Hello
  	hello!(); // prints Hello World
}
 
PREVIOUS NEXT
Tagged: #optional #arguments #rust
ADD COMMENT
Topic
Name
6+8 =