fn check_lang_files<F>(
    languages: &header::AcceptLanguage,
    filename: &str,
    closure: &mut F,
) -> Result<HttpResponse, ()>
where
    F: FnMut(&str) -> Option<HttpResponse>,
{
    let path = Path::new(filename);
    let file_stem = path
        .file_stem()
        .ok_or_else(|| HttpResponse::BadRequest().finish())
        .map_err(|_| {})?
        .to_string_lossy();
    let file_ext = path.extension();

    for lang in languages.iter().map(|e| format!("{}", e.item)) {
        // Build a new filename: main.ext -> main.lang.ext
        let lang_file = if let Some(ext) = file_ext {
            format!("{}.{}.{}", file_stem, lang, ext.to_string_lossy())
        } else {
            format!("{}.{}", file_stem, lang)
        };

        if let Some(response) = closure(&lang_file) {
            return Ok(response);
        }
    }

    Err(())
}
// Helper to figure out if we can use a language specific version of
// a given path.
Helper to figure out if we can use a language specific version of
a given path.
Helper to figure out if we can use a language specific version of a given path .
fn check_lang_files<F>(
    languages: &header::AcceptLanguage,
    filename: &str,
    closure: &mut F,
) -> Result<HttpResponse, ()>
where
    F: FnMut(&str) -> Option<HttpResponse>,
{
    let path = Path::new(filename);
    let file_stem = path
        .file_stem()
        .ok_or_else(|| HttpResponse::BadRequest().finish())
        .map_err(|_| {})?
        .to_string_lossy();
    let file_ext = path.extension();
    for lang in languages.iter().map(|e| format!("{}", e.item)) {
        // Build a new filename: main.ext -> main.lang.ext
        let lang_file = if let Some(ext) = file_ext {
            format!("{}.{}.{}", file_stem, lang, ext.to_string_lossy())
        } else {
            format!("{}.{}", file_stem, lang)
        };
        if let Some(response) = closure(&lang_file) {
            return Ok(response);
        }
    }
    Err(())
}
fn check_lang_files < F > ( languages : & header :: AcceptLanguage , filename : & str , closure : & mut F , ) -> Result < HttpResponse , ( ) > where F : FnMut ( & str ) -> Option < HttpResponse > , { let path = Path :: new ( filename ) ; let file_stem = path . file_stem ( ) . ok_or_else ( | | HttpResponse :: BadRequest ( ) . finish ( ) ) . map_err ( | _ | { } ) ? . to_string_lossy ( ) ; let file_ext = path . extension ( ) ; for lang in languages . iter ( ) . map ( | e | format ! ( " " e item ) ) { // Build a new filename: main.ext -> main.lang.ext let lang_file = if let Some ( ext ) = file_ext { format ! ( " " file_stem lang ext to_string_lossy ( ) ) } else { format ! ( " " file_stem lang ) } ; if let Some ( response ) = closure ( & lang_file ) { return Ok ( response ) ; } } Err ( ( ) ) }
Helper to figure out if we can use a language specific version of
a given path.
Helper to figure out if we can use a language specific version of a given path .
languages
&header::AcceptLanguage
filename
&str
closure
&mut F
languages
&header::AcceptLanguage
filename
&str
closure
&mut F