forked from gentoo-utils/gentoo-utils
allow Cpv type to have a slot
This commit is contained in:
@@ -119,6 +119,7 @@ pub struct Cpv {
|
||||
category: Category,
|
||||
name: Name,
|
||||
version: Version,
|
||||
slot: Option<Slot>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Get, PartialEq, Eq)]
|
||||
@@ -572,7 +573,13 @@ impl fmt::Display for Cp {
|
||||
|
||||
impl fmt::Display for Cpv {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}/{}-{}", &self.category, &self.name, &self.version)
|
||||
write!(f, "{}/{}-{}", &self.category, &self.name, &self.version)?;
|
||||
|
||||
if let Some(slot) = self.slot.as_ref() {
|
||||
write!(f, ":{slot}")?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -351,10 +351,12 @@ impl<'a> Parseable<'a, &'a str> for Cpv {
|
||||
Category::parser()
|
||||
.and(Name::parser().preceded_by(tag("/")))
|
||||
.and(Version::parser().preceded_by(tag("-")))
|
||||
.map(|((category, name), version)| Cpv {
|
||||
.and(Slot::parser().preceded_by(tag(":")).opt())
|
||||
.map(|(((category, name), version), slot)| Cpv {
|
||||
category,
|
||||
name,
|
||||
version,
|
||||
slot,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -479,4 +481,11 @@ mod test {
|
||||
|
||||
Atom::parser().check_finished(it).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cpv_with_slot() {
|
||||
let it = InputIter::new("foo/bar-1.0:slot/sub=");
|
||||
|
||||
Cpv::parser().check_finished(it).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user