fn is_enclosed(&self, first_char:char, last_char:char) -> bool {
        let text = self.as_ref();
        if first_char.is_ascii() && last_char.is_ascii() {
            let bytes = text.as_bytes();
            bytes.first() == Some(&(first_char as u8)) && bytes.last() == Some(&(last_char as u8))
        } else {
            let mut chars = text.chars();
            let first     = chars.next();
            let last      = chars.last().or(first);
            first == Some(first_char) && last == Some(last_char)
        }
    }
/// Check if given string starts and ends with given characters.
///
/// Optimized to be O(1) if both characters are within ASCII range.
Check if given string starts and ends with given characters.
Optimized to be O(1) if both characters are within ASCII range.
Check if given string starts and ends with given characters . Optimized to be O ( 1 ) if both characters are within ASCII range .
fn is_enclosed(&self, first_char:char, last_char:char) -> bool {
        let text = self.as_ref();
        if first_char.is_ascii() && last_char.is_ascii() {
            let bytes = text.as_bytes();
            bytes.first() == Some(&(first_char as u8)) && bytes.last() == Some(&(last_char as u8))
        } else {
            let mut chars = text.chars();
            let first     = chars.next();
            let last      = chars.last().or(first);
            first == Some(first_char) && last == Some(last_char)
        }
    }
fn is_enclosed ( & self , first_char : char , last_char : char ) -> bool { let text = self . as_ref ( ) ; if first_char . is_ascii ( ) && last_char . is_ascii ( ) { let bytes = text . as_bytes ( ) ; bytes . first ( ) == Some ( & ( first_char as u8 ) ) && bytes . last ( ) == Some ( & ( last_char as u8 ) ) } else { let mut chars = text . chars ( ) ; let first = chars . next ( ) ; let last = chars . last ( ) . or ( first ) ; first == Some ( first_char ) && last == Some ( last_char ) } }
Check if given string starts and ends with given characters.
Check if given string starts and ends with given characters .
&self
first_char
char
last_char
char
&self
first_char
char
last_char
char