fn camel_to_snake(camel: &str) -> String {
    let mut chars = camel.chars().peekable();
    let mut snake = String::new();
    // It is assured that input is not empty.
    snake.push((chars.next().unwrap() as u8 + 32) as char);
    while let Some(&ch) = chars.peek() {
        chars.next();
        if ch.is_uppercase() {
            match chars.peek() {
                Some(ch_next) if ch_next.is_uppercase() => {
                    // Capital in a sequence of capitals.
                    snake.push((ch as u8 + 32) as char);
                }
                Some(ch_next) if ch_next.is_lowercase() => {
                    // Start of new word
                    // Insert '_'
                    snake.push('_');
                    snake.push((ch as u8 + 32) as char);
                }
                _ => (),
            }
        } else {
            snake.push(ch);
        }
    }
    snake
}
/// Convert camel case name to snake case name.
Convert camel case name to snake case name.
Convert camel case name to snake case name .
fn camel_to_snake(camel: &str) -> String {
    let mut chars = camel.chars().peekable();
    let mut snake = String::new();
    // It is assured that input is not empty.
    snake.push((chars.next().unwrap() as u8 + 32) as char);
    while let Some(&ch) = chars.peek() {
        chars.next();
        if ch.is_uppercase() {
            match chars.peek() {
                Some(ch_next) if ch_next.is_uppercase() => {
                    // Capital in a sequence of capitals.
                    snake.push((ch as u8 + 32) as char);
                }
                Some(ch_next) if ch_next.is_lowercase() => {
                    // Start of new word
                    // Insert '_'
                    snake.push('_');
                    snake.push((ch as u8 + 32) as char);
                }
                _ => (),
            }
        } else {
            snake.push(ch);
        }
    }
    snake
}
fn camel_to_snake ( camel : & str ) -> String { let mut chars = camel . chars ( ) . peekable ( ) ; let mut snake = String :: new ( ) ; // It is assured that input is not empty. snake . push ( ( chars . next ( ) . unwrap ( ) as u8 + 32 ) as char ) ; while let Some ( & ch ) = chars . peek ( ) { chars . next ( ) ; if ch . is_uppercase ( ) { match chars . peek ( ) { Some ( ch_next ) if ch_next . is_uppercase ( ) => { // Capital in a sequence of capitals. snake . push ( ( ch as u8 + 32 ) as char ) ; } Some ( ch_next ) if ch_next . is_lowercase ( ) => { // Start of new word // Insert '_' snake . push ( '_' ) ; snake . push ( ( ch as u8 + 32 ) as char ) ; } _ => ( ) , } } else { snake . push ( ch ) ; } } snake }
Convert camel case name to snake case name.
Convert camel case name to snake case name .
camel
&str
camel
&str