fn look_up_info<'a>(
    input: &'a Path,
    destination: &Path,
    destination_files: &[String],
    indices: &mut dyn Iterator<Item = u32>,
) -> Result<ImageInfo<'a>> {
    let file_stem = input
        .file_stem()
        .and_then(|f| f.to_str())
        .ok_or_else(|| anyhow!("Failed to get filename for {:?}", input))?;

    // If the file is foo.png, we're looking for an existing file named NNNN-foo.bin, where
    // N is a decimal digit. If it exists, we'll overwrite it, otherwise we'll use the next index.
    let re = Regex::new(&format!(r"^\d+-{}.bin$", escape(file_stem)))
        .with_context(|| format!("Failed to construct regex for {:?}", input))?;

    let existing_name = destination_files.iter().find(|x| re.is_match(x));

    let output = destination.join(existing_name.map(PathBuf::from).unwrap_or_else(|| {
        PathBuf::from(format!(
            "{:04}-{}.bin",
            indices.next().expect("Ran out of indices"),
            file_stem
        ))
    }));

    Ok(ImageInfo { input, output })
}
/// Looks up the destination mapping for a source image.
/// if it already exists in the output directory, that filename will be returned.
/// Otherwise, it will be assigned the next available index.
Looks up the destination mapping for a source image.
if it already exists in the output directory, that filename will be returned.
Otherwise, it will be assigned the next available index.
Looks up the destination mapping for a source image . if it already exists in the output directory that filename will be returned . Otherwise it will be assigned the next available index .
fn look_up_info<'a>(
    input: &'a Path,
    destination: &Path,
    destination_files: &[String],
    indices: &mut dyn Iterator<Item = u32>,
) -> Result<ImageInfo<'a>> {
    let file_stem = input
        .file_stem()
        .and_then(|f| f.to_str())
        .ok_or_else(|| anyhow!("Failed to get filename for {:?}", input))?;
    // If the file is foo.png, we're looking for an existing file named NNNN-foo.bin, where
    // N is a decimal digit. If it exists, we'll overwrite it, otherwise we'll use the next index.
    let re = Regex::new(&format!(r"^\d+-{}.bin$", escape(file_stem)))
        .with_context(|| format!("Failed to construct regex for {:?}", input))?;
    let existing_name = destination_files.iter().find(|x| re.is_match(x));
    let output = destination.join(existing_name.map(PathBuf::from).unwrap_or_else(|| {
        PathBuf::from(format!(
            "{:04}-{}.bin",
            indices.next().expect("Ran out of indices"),
            file_stem
        ))
    }));
    Ok(ImageInfo { input, output })
}
fn look_up_info < ' a > ( input : & ' a Path , destination : & Path , destination_files : & [ String ] , indices : & mut dyn Iterator < Item = u32 > , ) -> Result < ImageInfo < ' a > > { let file_stem = input . file_stem ( ) . and_then ( | f | f . to_str ( ) ) . ok_or_else ( | | anyhow ! ( " " input ) ) ? ; // If the file is foo.png, we're looking for an existing file named NNNN-foo.bin, where // N is a decimal digit. If it exists, we'll overwrite it, otherwise we'll use the next index. let re = Regex :: new ( & format ! ( r"^\d+-{}.bin$" escape ( file_stem ) ) ) . with_context ( | | format ! ( " " input ) ) ? ; let existing_name = destination_files . iter ( ) . find ( | x | re . is_match ( x ) ) ; let output = destination . join ( existing_name . map ( PathBuf :: from ) . unwrap_or_else ( | | { PathBuf :: from ( format ! ( " " indices next ( ) expect ( " " ) file_stem ) ) } ) ) ; Ok ( ImageInfo { input , output } ) }
Looks up the destination mapping for a source image.
Looks up the destination mapping for a source image .
input
&'a Path
destination
&Path
destination_files
&[String]
indices
&mut dyn Iterator<Item = u32>