From 51d6b3039b37cf47346e096bd6a892a4e07927a5 Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Sun, 7 Aug 2022 18:37:45 +1000 Subject: [PATCH] Impl new fn `helpers::parse_version` Signed-off-by: Jiahao XU --- src/helpers.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/helpers.rs b/src/helpers.rs index 2e010244..b311f75d 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -8,6 +8,7 @@ use std::sync::Arc; use bytes::Bytes; use cargo_toml::Manifest; +use compact_str::format_compact; use futures_util::stream::Stream; use log::debug; use once_cell::sync::{Lazy, OnceCell}; @@ -86,6 +87,20 @@ pub async fn await_task(task: tokio::task::JoinHandle>) -> } } +pub fn parse_version(version: &str) -> Result { + // Treat 0.1.2 as =0.1.2 + if version + .chars() + .next() + .map(|ch| ch.is_ascii_digit()) + .unwrap_or(false) + { + format_compact!("={version}").parse() + } else { + version.parse() + } +} + /// Load binstall metadata from the crate `Cargo.toml` at the provided path pub fn load_manifest_path>( manifest_path: P,