fn next_installed_version(
    dir: &Path,
    current_version: &ProtocolVersion,
) -> Result<ProtocolVersion, Error> {
    let max_version =
        ProtocolVersion::from_parts(u32::max_value(), u32::max_value(), u32::max_value());

    let mut next_version = max_version;
    let mut read_version = false;
    for entry in fs::read_dir(dir).map_err(|error| Error::ReadDir {
        dir: dir.to_path_buf(),
        error,
    })? {
        let path = match entry {
            Ok(dir_entry) => dir_entry.path(),
            Err(error) => {
                debug!(dir=%dir.display(), %error, "bad entry while reading dir");
                continue;
            }
        };

        let subdir_name = match path.file_name() {
            Some(name) => name.to_string_lossy().replace("_", "."),
            None => continue,
        };

        let version = match ProtocolVersion::from_str(&subdir_name) {
            Ok(version) => version,
            Err(error) => {
                trace!(%error, path=%path.display(), "failed to get a version");
                continue;
            }
        };

        if version > *current_version && version < next_version {
            next_version = version;
        }
        read_version = true;
    }

    if !read_version {
        return Err(Error::NoVersionSubdirFound {
            dir: dir.to_path_buf(),
        });
    }

    if next_version == max_version {
        next_version = *current_version;
    }

    Ok(next_version)
}
/// Iterates the given path, returning the subdir representing the immediate next SemVer version
/// after `current_version`.
///
/// Subdir names should be semvers with dots replaced with underscores.
Iterates the given path, returning the subdir representing the immediate next SemVer version
after `current_version`.

Subdir names should be semvers with dots replaced with underscores.
Iterates the given path returning the subdir representing the immediate next SemVer version after ` current_version ` . Subdir names should be semvers with dots replaced with underscores .
fn next_installed_version(
    dir: &Path,
    current_version: &ProtocolVersion,
) -> Result<ProtocolVersion, Error> {
    let max_version =
        ProtocolVersion::from_parts(u32::max_value(), u32::max_value(), u32::max_value());
    let mut next_version = max_version;
    let mut read_version = false;
    for entry in fs::read_dir(dir).map_err(|error| Error::ReadDir {
        dir: dir.to_path_buf(),
        error,
    })? {
        let path = match entry {
            Ok(dir_entry) => dir_entry.path(),
            Err(error) => {
                debug!(dir=%dir.display(), %error, "bad entry while reading dir");
                continue;
            }
        };
        let subdir_name = match path.file_name() {
            Some(name) => name.to_string_lossy().replace("_", "."),
            None => continue,
        };
        let version = match ProtocolVersion::from_str(&subdir_name) {
            Ok(version) => version,
            Err(error) => {
                trace!(%error, path=%path.display(), "failed to get a version");
                continue;
            }
        };
        if version > *current_version && version < next_version {
            next_version = version;
        }
        read_version = true;
    }
    if !read_version {
        return Err(Error::NoVersionSubdirFound {
            dir: dir.to_path_buf(),
        });
    }
    if next_version == max_version {
        next_version = *current_version;
    }
    Ok(next_version)
}
fn next_installed_version ( dir : & Path , current_version : & ProtocolVersion , ) -> Result < ProtocolVersion , Error > { let max_version = ProtocolVersion :: from_parts ( u32 :: max_value ( ) , u32 :: max_value ( ) , u32 :: max_value ( ) ) ; let mut next_version = max_version ; let mut read_version = false ; for entry in fs :: read_dir ( dir ) . map_err ( | error | Error :: ReadDir { dir : dir . to_path_buf ( ) , error , } ) ? { let path = match entry { Ok ( dir_entry ) => dir_entry . path ( ) , Err ( error ) => { debug ! ( dir dir display ( ) error " " ) ; continue ; } } ; let subdir_name = match path . file_name ( ) { Some ( name ) => name . to_string_lossy ( ) . replace ( " " , " " ) , None => continue , } ; let version = match ProtocolVersion :: from_str ( & subdir_name ) { Ok ( version ) => version , Err ( error ) => { trace ! ( error path path display ( ) " " ) ; continue ; } } ; if version > * current_version && version < next_version { next_version = version ; } read_version = true ; } if ! read_version { return Err ( Error :: NoVersionSubdirFound { dir : dir . to_path_buf ( ) , } ) ; } if next_version == max_version { next_version = * current_version ; } Ok ( next_version ) }
Iterates the given path, returning the subdir representing the immediate next SemVer version
after `current_version`.
Iterates the given path returning the subdir representing the immediate next SemVer version after ` current_version ` .
dir
&Path
current_version
&ProtocolVersion
dir
&Path
current_version
&ProtocolVersion