Skip to main content

find_latest_stable

Function find_latest_stable 

Source
pub fn find_latest_stable(versions: &[Box<dyn Version>]) -> Option<&dyn Version>
Expand description

Finds the latest stable version from a list of versions.

Returns the first version that is:

Assumes versions are sorted newest-first (as returned by registries).

§Examples

use deps_core::registry::{RemovalStatus, Version, find_latest_stable};
use deps_core::ConcreteVersion;
use std::any::Any;

struct MyVersion { version: ConcreteVersion, yanked: bool }

impl Version for MyVersion {
    fn version_string(&self) -> &ConcreteVersion { &self.version }
    fn removal_status(&self) -> RemovalStatus { RemovalStatus::from_yanked(self.yanked) }
    fn as_any(&self) -> &dyn Any { self }
}

let versions: Vec<Box<dyn Version>> = vec![
    Box::new(MyVersion { version: "2.0.0-alpha.1".into(), yanked: false }),
    Box::new(MyVersion { version: "1.5.0".into(), yanked: true }),
    Box::new(MyVersion { version: "1.4.0".into(), yanked: false }),
];

let latest = find_latest_stable(&versions);
assert_eq!(latest.map(|v| v.version_string().as_str()), Some("1.4.0"));