l8kyu/
strings.rs

1//!
2//! Modules categorized by Codewars labels - 8kyu *** Strings ***
3//!
4
5use shared::kata::*;
6
7/// Your goal is to write a function that removes the first and last
8/// characters of a string. You're given one parameter, the original string.
9/// Important: Your function should handle strings of any length ≥ 2 characters.
10/// For strings with exactly 2 characters, return an empty string.
11/// # Example
12/// ``` remove_char("eloquent"); ``` <br>
13/// returns "loquen"
14pub fn remove_char(s: &str) -> String {
15    let kata = Kata {
16        level: Level::L8kyu,
17        tags: vec![Tag::Strings, Tag::Fundamentals],
18        description: String::from("Remove First and Last Character"),
19    };
20
21    println!(
22        "Level: {:?}, Tags: {:?}, Description: {}",
23        kata.level, kata.tags, kata.description
24    );
25
26    s[1..s.len() - 1].to_string()
27}
28
29/// Implement a function which convert the given boolean value into its
30/// string representation.
31/// # Example
32/// ``` boolean_to_string(true); ``` <br>
33/// returns "true"
34pub fn boolean_to_string(b: bool) -> String {
35    let kata = Kata {
36        level: Level::L8kyu,
37        tags: vec![Tag::Strings, Tag::Fundamentals],
38        description: String::from("Convert a Boolean to a String"),
39    };
40
41    println!(
42        "Level: {:?}, Tags: {:?}, Description: {}",
43        kata.level, kata.tags, kata.description
44    );
45
46    b.to_string()
47}