summaryrefslogtreecommitdiffstats
path: root/src/package/name.rs
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2020-10-28 13:17:46 +0100
committerMatthias Beyer <mail@beyermatthias.de>2020-10-28 13:49:52 +0100
commit09113dcf7a4cf6124c2f88178558062b99c77863 (patch)
tree7eff7c6dec27a6ec7ddc994fcc571a8926b07508 /src/package/name.rs
parent53a77eb46b4152def2d0e4518151353f80656eee (diff)
Split parser implementation
This commit splits the parser implementation and moves the code to the types it parses. This way we reduce the code duplication. A util module was added for the trivial parser functions. Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'src/package/name.rs')
-rw-r--r--src/package/name.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/package/name.rs b/src/package/name.rs
index f42c827..44b3f07 100644
--- a/src/package/name.rs
+++ b/src/package/name.rs
@@ -1,5 +1,6 @@
use std::ops::Deref;
use serde::Deserialize;
+use pom::parser::Parser as PomParser;
#[derive(Deserialize, Clone, Debug, Hash, Eq, PartialEq, Ord, PartialOrd)]
#[serde(transparent)]
@@ -23,3 +24,13 @@ impl std::fmt::Display for PackageName {
self.0.fmt(f)
}
}
+
+impl PackageName {
+ pub fn parser<'a>() -> PomParser<'a, u8, Self> {
+ use crate::util::parser::*;
+ (letters() + ((letters() | numbers()).repeat(0..)))
+ .collect()
+ .convert(|b| String::from_utf8(b.to_vec()).map(Self::from))
+ }
+}
+