summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Turner <jturner.usa@gmail.com>2025-11-13 19:57:28 +0000
committerJohn Turner <jturner.usa@gmail.com>2025-11-13 19:57:28 +0000
commit36bdbbd8bc5b0a27ba1de797d67f9f2e0ae7680c (patch)
tree65763c277e1c40ab57537d645fb9eaa9da0c448c
parent0448a529264d1a27d741bc817de468f8d359072d (diff)
downloadgentoo-utils-36bdbbd8bc5b0a27ba1de797d67f9f2e0ae7680c.tar.gz
allow Cpv type to have a slot
-rw-r--r--src/atom/mod.rs9
-rw-r--r--src/atom/parsers.rs11
2 files changed, 18 insertions, 2 deletions
diff --git a/src/atom/mod.rs b/src/atom/mod.rs
index 6688665..11ca246 100644
--- a/src/atom/mod.rs
+++ b/src/atom/mod.rs
@@ -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(())
}
}
diff --git a/src/atom/parsers.rs b/src/atom/parsers.rs
index 4806857..37e18a7 100644
--- a/src/atom/parsers.rs
+++ b/src/atom/parsers.rs
@@ -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();
+ }
}