mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-20 20:48:43 +00:00
Impl new fn helpers::parse_version
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
20c7b61e7a
commit
51d6b3039b
1 changed files with 15 additions and 0 deletions
|
@ -8,6 +8,7 @@ use std::sync::Arc;
|
||||||
|
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use cargo_toml::Manifest;
|
use cargo_toml::Manifest;
|
||||||
|
use compact_str::format_compact;
|
||||||
use futures_util::stream::Stream;
|
use futures_util::stream::Stream;
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use once_cell::sync::{Lazy, OnceCell};
|
use once_cell::sync::{Lazy, OnceCell};
|
||||||
|
@ -86,6 +87,20 @@ pub async fn await_task<T>(task: tokio::task::JoinHandle<miette::Result<T>>) ->
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn parse_version(version: &str) -> Result<semver::VersionReq, semver::Error> {
|
||||||
|
// 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
|
/// Load binstall metadata from the crate `Cargo.toml` at the provided path
|
||||||
pub fn load_manifest_path<P: AsRef<Path>>(
|
pub fn load_manifest_path<P: AsRef<Path>>(
|
||||||
manifest_path: P,
|
manifest_path: P,
|
||||||
|
|
Loading…
Add table
Reference in a new issue