Module comparison

Module comparison 

Source
Expand description

Version comparison utilities and analysis functions.

The comparison module provides tools for analyzing and comparing semantic versions, finding newer versions, and determining latest releases from version collections. See the module documentation for detailed usage examples. Version comparison utilities for semantic version handling.

This module provides utilities for comparing semantic versions, checking for newer versions, and handling version parsing operations used throughout the dependency resolution process. It supports common version prefixes and provides error-handling for malformed version strings.

§Features

  • Semantic Version Parsing: Handles v1.2.3, version-1.2.3, release-1.2.3 formats
  • Version Comparison: Find newer versions and latest versions in collections
  • Prefix Handling: Automatically strips common version prefixes
  • Error Resilience: Gracefully handles malformed version strings

§Examples

use agpm_cli::version::comparison::VersionComparator;

let versions = vec![
    "v1.0.0".to_string(),
    "v1.1.0".to_string(),
    "v2.0.0".to_string(),
    "version-1.0.1".to_string(),
];

// Check if there are newer versions
let has_newer = VersionComparator::has_newer_version("v1.0.0", &versions)?;
assert!(has_newer);

// Get the latest version
let latest = VersionComparator::get_latest(&versions)?
    .expect("Should find latest version");
assert_eq!(latest, "v2.0.0");

// Get all newer versions than current
let newer = VersionComparator::get_newer_versions("v1.0.0", &versions)?;
assert_eq!(newer.len(), 3); // v1.1.0, v2.0.0, version-1.0.1

Structs§

VersionComparator
Version comparison utilities for semantic version operations.