1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//! This crate provides functions needed for Hello World applications.

/// This function takes an optional name and returns a greeting
///
/// # Examples
///
/// If no name is given, it will return the default greeting
///
/// ```
/// use hello_world_x_rust_x_library::greet;
///
/// assert_eq!("Hello, world!", greet(None));
/// ```
///
/// If a name is given, it will return a customized greeting
///
/// ```
/// use hello_world_x_rust_x_library::greet;
///
/// assert_eq!("Hello, intrepion!", greet(Some("intrepion")));
/// ```
pub fn greet(name: Option<&str>) -> String {
    match name {
        Some(name) => format!("Hello, {}!", name),
        None => "Hello, world!".to_string(),
    }
}