summaryrefslogtreecommitdiffstats
path: root/src/package/version.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/package/version.rs')
-rw-r--r--src/package/version.rs22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/package/version.rs b/src/package/version.rs
index 0c3f7f6..9705c8d 100644
--- a/src/package/version.rs
+++ b/src/package/version.rs
@@ -25,10 +25,6 @@ pub struct PackageVersionConstraint {
}
impl PackageVersionConstraint {
- pub fn new(s: String) -> Result<Self> {
- Self::parser().parse(s.as_bytes()).map_err(Error::from)
- }
-
fn parser<'a>() -> PomParser<'a, u8, Self> {
(pom::parser::sym(b'=') + PackageVersion::parser())
.convert(|(constraint, version)| {
@@ -53,6 +49,24 @@ impl PackageVersionConstraint {
}
}
+impl std::convert::TryFrom<String> for PackageVersionConstraint {
+ type Error = anyhow::Error;
+
+ fn try_from(s: String) -> Result<Self> {
+ Self::try_from(&s as &str)
+ }
+}
+
+impl std::convert::TryFrom<&str> for PackageVersionConstraint {
+ type Error = anyhow::Error;
+
+ fn try_from(s: &str) -> Result<Self> {
+ PackageVersionConstraint::parser()
+ .parse(s.as_bytes())
+ .map_err(Error::from)
+ }
+}
+
#[derive(
parse_display::Display,
Serialize,