1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
use semver::Version; use std::cmp::Ordering; use std::ffi::OsStr; use std::str::FromStr; pub trait OsStrExt { fn to_str_direct(&self) -> &str; fn to_string_direct(&self) -> String; } impl OsStrExt for OsStr { fn to_str_direct(&self) -> &str { self.to_str().unwrap() } fn to_string_direct(&self) -> String { self.to_str().unwrap().to_string() } } pub trait VersionCompareTrait { fn cmp_version(&self, version: &str) -> Option<Ordering>; } impl VersionCompareTrait for String { fn cmp_version(&self, version: &str) -> Option<Ordering> { Version::from_str(&self).partial_cmp(&Version::from_str(version)) } }