1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
const SEPARATORS: &[char] = &[' ', '_', '-'];

pub fn to_train_case<S: AsRef<str>>(input: S) -> String {
    let items: Vec<String> = String::from(input.as_ref())
        .split(SEPARATORS)
        .map(ToString::to_string)
        .collect();

    items.join("_").to_uppercase()
}

#[cfg(test)]
mod test {
    use super::*;

    #[test]
    fn test_to_train_case() {
        assert_eq!(to_train_case("omg-OMG_omg123 omg"), "OMG_OMG_OMG123_OMG")
    }
}