Eliminate word_or_empty methods.

To get rid of the `Ident::empty` uses.

This requires introducing `PathParser::word_sym`, as an alternative to
`PathParser::word`.
This commit is contained in:
Nicholas Nethercote
2025-04-21 07:52:30 +10:00
parent ab62d56603
commit d81472f266
5 changed files with 54 additions and 60 deletions

View File

@@ -78,8 +78,8 @@ impl<'a> PathParser<'a> {
(self.len() == 1).then(|| **self.segments().next().as_ref().unwrap())
}
pub fn word_or_empty(&self) -> Ident {
self.word().unwrap_or_else(Ident::empty)
pub fn word_sym(&self) -> Option<Symbol> {
self.word().map(|ident| ident.name)
}
/// Asserts that this MetaItem is some specific word.
@@ -284,11 +284,6 @@ impl<'a> MetaItemParser<'a> {
Some(self.word()?.0)
}
/// Like [`word`](Self::word), but returns an empty symbol instead of None
pub fn word_or_empty_without_args(&self) -> Ident {
self.word_or_empty().0
}
/// Asserts that this MetaItem starts with a word, or single segment path.
///
/// Some examples:
@@ -300,12 +295,6 @@ impl<'a> MetaItemParser<'a> {
Some((path.word()?, args))
}
/// Like [`word`](Self::word), but returns an empty symbol instead of None
pub fn word_or_empty(&self) -> (Ident, &ArgParser<'a>) {
let (path, args) = self.deconstruct();
(path.word().unwrap_or(Ident::empty()), args)
}
/// Asserts that this MetaItem starts with some specific word.
///
/// See [`word`](Self::word) for examples of what a word is.