Search
 
SCRIPT & CODE EXAMPLE
 

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
}
Comment

PREVIOUS NEXT
Code Example
Rust :: rust iterate vector backwards 
Rust :: armanriazi•rust•concept•superpowers 
Rust :: armanriazi•rust•error•E0282•type annotations needed 
Rust :: rust get input on the same line as question 
Rust :: how to make map in rust language 
Rust :: closure type in rust 
Rust :: what is () in rust 
Rust :: rust compiler 
Rust :: unwrap_or_else in rust 
Rust :: convert path to pathbuf 
Rust :: rust BMI 
Rust :: armanriazi•rust•error•E0308•mismatched types 
Rust :: armanriazi•rust•interior-mutability•cell 
Rust :: rust print i8 
Rust :: armanriazi•rust•trait•external•implement•coherence•orphan 
Rust :: search in dir rust 
Rust :: trait in rust 
Lua :: roblox how to get random object from a table 
Lua :: lua for each in table 
Lua :: roblox loop players 
Lua :: roblox how to find something in table 
Lua :: roblox rotate model 
Lua :: roblox number between 1 and 10 
Lua :: roblox text color 
Lua :: roblox player chatter event 
Lua :: roblox format string 
Lua :: lua prin type of variable 
Lua :: open while loop lua 
Matlab :: sum vs symsum in matlab script 
Matlab :: sin in scilab 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =