Apply more suggestions.

This commit is contained in:
Tom Alexander 2023-10-16 16:51:26 -04:00
parent 728f79b86c
commit 4ba0e3611b
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
3 changed files with 18 additions and 31 deletions

View File

@ -42,9 +42,9 @@ pub(crate) fn in_section<'b, 'g, 'r, 's, 'x>(
}
/// Checks if we are currently an immediate child of the given section type
pub(crate) fn immediate_in_section<'b, 'g, 'r, 's, 'x>(
context: RefContext<'b, 'g, 'r, 's>,
section_name: &'x str,
pub(crate) fn immediate_in_section(
context: RefContext<'_, '_, '_, '_>,
section_name: &str,
) -> bool {
for thing in context.iter() {
match thing {
@ -133,7 +133,7 @@ pub(crate) fn start_of_line<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, ()>
Ok((input, ()))
} else {
Err(nom::Err::Error(CustomError::MyError(MyError(
"Not at start of line".into(),
"Not at start of line",
))))
}
}
@ -156,7 +156,7 @@ fn _preceded_by_whitespace<'s>(
.unwrap_or(allow_start_of_file)
{
return Err(nom::Err::Error(CustomError::MyError(MyError(
"Must be preceded by a whitespace character.".into(),
"Must be preceded by a whitespace character.",
))));
}
Ok((input, ()))
@ -198,9 +198,9 @@ pub(crate) fn text_until_exit<'b, 'g, 'r, 's>(
#[allow(dead_code)]
fn not_yet_implemented() -> Res<OrgSource<'static>, ()> {
return Err(nom::Err::Error(CustomError::MyError(MyError(
"Not implemented yet.".into(),
))));
Err(nom::Err::Error(CustomError::MyError(MyError(
"Not implemented yet.",
))))
}
#[allow(dead_code)]
@ -234,29 +234,27 @@ where
/// Match single space or tab.
///
/// In org-mode syntax, spaces and tabs are often (but not always!) interchangeable.
pub(crate) fn org_space<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, char> {
pub(crate) fn org_space(input: OrgSource<'_>) -> Res<OrgSource<'_>, char> {
one_of(" \t")(input)
}
/// Matches a single space, tab, line ending, or end of file.
///
/// In org-mode syntax there are often delimiters that could be any whitespace at all or the end of file.
pub(crate) fn org_space_or_line_ending<'s>(
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, OrgSource<'s>> {
pub(crate) fn org_space_or_line_ending(input: OrgSource<'_>) -> Res<OrgSource<'_>, OrgSource<'_>> {
alt((recognize(org_space), org_line_ending))(input)
}
/// Match a line break or the end of the file.
///
/// In org-mode syntax, the end of the file can serve the same purpose as a line break syntactically.
pub(crate) fn org_line_ending<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
pub(crate) fn org_line_ending(input: OrgSource<'_>) -> Res<OrgSource<'_>, OrgSource<'_>> {
alt((line_ending, eof))(input)
}
/// Match the whitespace at the beginning of a line and give it an indentation level.
pub(crate) fn indentation_level<'b, 'g, 'r, 's>(
context: RefContext<'b, 'g, 'r, 's>,
pub(crate) fn indentation_level<'s>(
context: RefContext<'_, '_, '_, 's>,
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, (IndentationLevel, OrgSource<'s>)> {
let (remaining, leading_whitespace) = space0(input)?;

View File

@ -19,7 +19,7 @@ pub struct AffiliatedKeyword<'s> {
pub value: AffiliatedKeywordValue<'s>,
}
#[derive(Debug)]
#[derive(Debug, Default)]
pub struct AffiliatedKeywords<'s> {
pub(crate) keywords: BTreeMap<String, AffiliatedKeywordValue<'s>>,
}
@ -27,11 +27,3 @@ pub struct AffiliatedKeywords<'s> {
pub trait GetAffiliatedKeywords<'s> {
fn get_affiliated_keywords<'a>(&'a self) -> &'a AffiliatedKeywords<'s>;
}
impl<'s> Default for AffiliatedKeywords<'s> {
fn default() -> Self {
AffiliatedKeywords {
keywords: BTreeMap::new(),
}
}
}

View File

@ -101,9 +101,8 @@ impl<'s> Heading<'s> {
_ => None,
})
.flat_map(|section| section.children.iter())
.take_while(|element| match element {
Element::Planning(_) | Element::PropertyDrawer(_) => true,
_ => false,
.take_while(|element| {
matches!(element, Element::Planning(_) | Element::PropertyDrawer(_))
})
.find_map(|element| match element {
Element::PropertyDrawer(property_drawer) => Some(property_drawer),
@ -121,10 +120,8 @@ impl<'s> Document<'s> {
.iter()
.flat_map(|zeroth_section| zeroth_section.children.iter());
let property_drawer = zeroth_section_children
.take_while(|element| match element {
Element::Comment(_) => true,
Element::PropertyDrawer(_) => true,
_ => false,
.take_while(|element| {
matches!(element, Element::Comment(_) | Element::PropertyDrawer(_))
})
.find_map(|element| match element {
Element::PropertyDrawer(property_drawer) => Some(property_drawer),