pub(crate) fn format_snippet(snippet: &str, config: &Config) -> Option<FormattedSnippet> {
    let mut config = config.clone();
    std::panic::catch_unwind(move || {
        config.set().hide_parse_errors(true);

        let result = {
            let input = Input::Text(snippet.into());
            crate::format(
                input,
                &config,
                OperationSetting {
                    verbosity: Verbosity::Quiet,
                    ..OperationSetting::default()
                },
            )
        };
        match result {
            Ok(report) if !report.has_errors() => {
                match report.format_result_as_rc().borrow().iter().next() {
                    Some((_, format_result))
                        if format_result.all_errors().count() == 0
                            && !format_result.formatted_text().is_empty() =>
                    {
                        Some(format_result.formatted_snippet().clone())
                    }
                    _ => None,
                }
            }
            _ => None,
        }
    })
    // Discard panics encountered while formatting the snippet
    // The ? operator is needed to remove the extra Option
    .ok()?
}
/// Format the given snippet. The snippet is expected to be *complete* code.
/// When we cannot parse the given snippet, this function returns `None`.
Format the given snippet. The snippet is expected to be *complete* code.
When we cannot parse the given snippet, this function returns `None`.
Format the given snippet . The snippet is expected to be * complete * code . When we cannot parse the given snippet this function returns ` None ` .
pub(crate) fn format_snippet(snippet: &str, config: &Config) -> Option<FormattedSnippet> {
    let mut config = config.clone();
    std::panic::catch_unwind(move || {
        config.set().hide_parse_errors(true);
        let result = {
            let input = Input::Text(snippet.into());
            crate::format(
                input,
                &config,
                OperationSetting {
                    verbosity: Verbosity::Quiet,
                    ..OperationSetting::default()
                },
            )
        };
        match result {
            Ok(report) if !report.has_errors() => {
                match report.format_result_as_rc().borrow().iter().next() {
                    Some((_, format_result))
                        if format_result.all_errors().count() == 0
                            && !format_result.formatted_text().is_empty() =>
                    {
                        Some(format_result.formatted_snippet().clone())
                    }
                    _ => None,
                }
            }
            _ => None,
        }
    })
    // Discard panics encountered while formatting the snippet
    // The ? operator is needed to remove the extra Option
    .ok()?
}
pub ( crate ) fn format_snippet ( snippet : & str , config : & Config ) -> Option < FormattedSnippet > { let mut config = config . clone ( ) ; std :: panic :: catch_unwind ( move | | { config . set ( ) . hide_parse_errors ( true ) ; let result = { let input = Input :: Text ( snippet . into ( ) ) ; crate :: format ( input , & config , OperationSetting { verbosity : Verbosity :: Quiet , .. OperationSetting :: default ( ) } , ) } ; match result { Ok ( report ) if ! report . has_errors ( ) => { match report . format_result_as_rc ( ) . borrow ( ) . iter ( ) . next ( ) { Some ( ( _ , format_result ) ) if format_result . all_errors ( ) . count ( ) == 0 && ! format_result . formatted_text ( ) . is_empty ( ) => { Some ( format_result . formatted_snippet ( ) . clone ( ) ) } _ => None , } } _ => None , } } ) // Discard panics encountered while formatting the snippet // The ? operator is needed to remove the extra Option . ok ( ) ? }
Format the given snippet.
Format the given snippet .
snippet
&str
config
&Config
snippet
&str
config
&Config