fn format_char_str(
    s: &str,
    length: Option<usize>,
    fail_on_len: bool,
    white_space: CharWhiteSpace,
) -> Result<String, anyhow::Error> {
    Ok(match length {
        // Note that length is 1-indexed, so finding `None` means the string's
        // characters don't exceed the length, while finding `Some` means it
        // does.
        Some(l) => match s.char_indices().nth(l) {
            None => white_space.process_str(s, length),
            Some((idx, _)) => {
                if !fail_on_len || s[idx..].chars().all(|c| c.is_ascii_whitespace()) {
                    white_space.process_str(&s[..idx], length)
                } else {
                    bail!("{} exceeds maximum length of {}", s, l)
                }
            }
        },
        None => white_space.process_str(s, None),
    })
}
/// Returns `s` as a `String` with options to enforce char and varchar
/// semantics.
///
/// # Arguments
/// * `s` - The `str` to format
/// * `length` - An optional maximum length for the string
/// * `fail_on_len` - Return an error if `s`'s character count exceeds the
///   specified maximum length.
/// * `white_space` - Express how to handle trailing whitespace on `s`
Returns `s` as a `String` with options to enforce char and varchar
semantics.
Returns ` s ` as a ` String ` with options to enforce char and varchar semantics .
fn format_char_str(
    s: &str,
    length: Option<usize>,
    fail_on_len: bool,
    white_space: CharWhiteSpace,
) -> Result<String, anyhow::Error> {
    Ok(match length {
        // Note that length is 1-indexed, so finding `None` means the string's
        // characters don't exceed the length, while finding `Some` means it
        // does.
        Some(l) => match s.char_indices().nth(l) {
            None => white_space.process_str(s, length),
            Some((idx, _)) => {
                if !fail_on_len || s[idx..].chars().all(|c| c.is_ascii_whitespace()) {
                    white_space.process_str(&s[..idx], length)
                } else {
                    bail!("{} exceeds maximum length of {}", s, l)
                }
            }
        },
        None => white_space.process_str(s, None),
    })
}
fn format_char_str ( s : & str , length : Option < usize > , fail_on_len : bool , white_space : CharWhiteSpace , ) -> Result < String , anyhow :: Error > { Ok ( match length { // Note that length is 1-indexed, so finding `None` means the string's // characters don't exceed the length, while finding `Some` means it // does. Some ( l ) => match s . char_indices ( ) . nth ( l ) { None => white_space . process_str ( s , length ) , Some ( ( idx , _ ) ) => { if ! fail_on_len || s [ idx .. ] . chars ( ) . all ( | c | c . is_ascii_whitespace ( ) ) { white_space . process_str ( & s [ .. idx ] , length ) } else { bail ! ( " " s l ) } } } , None => white_space . process_str ( s , None ) , } ) }
Returns `s` as a `String` with options to enforce char and varchar
semantics.
Returns ` s ` as a ` String ` with options to enforce char and varchar semantics .
s
&str
length
Option<usize>
fail_on_len
bool
white_space
CharWhiteSpace
s
&str
length
Option<usize>
fail_on_len
bool
white_space
CharWhiteSpace