refacotr(orgize): remove more anonymous lifetimes

This commit is contained in:
PoiScript 2019-10-09 15:56:25 +08:00
parent 0c76fd80f6
commit 5d26466e07
21 changed files with 46 additions and 58 deletions

View file

@ -171,7 +171,7 @@ pub fn parse_block_element(input: &str) -> Option<(&str, (&str, Option<&str>, &s
#[inline]
fn parse_block_element_internal<'a, E: ParseError<&'a str>>(
input: &'a str,
) -> IResult<&'a str, (&'a str, Option<&'a str>, &'a str), E> {
) -> IResult<&str, (&str, Option<&str>, &str), E> {
let (input, name) = preceded(tag_no_case("#+BEGIN_"), alpha1)(input)?;
let (input, args) = line(input)?;
let end_line = format!("#+END_{}", name);

View file

@ -44,7 +44,7 @@ pub enum Clock<'a> {
}
impl Clock<'_> {
pub(crate) fn parse(input: &str) -> Option<(&str, Clock<'_>)> {
pub(crate) fn parse(input: &str) -> Option<(&str, Clock)> {
parse_clock::<()>(input).ok()
}
@ -100,7 +100,7 @@ impl Clock<'_> {
}
/// Constructs a timestamp from the clock.
pub fn value(&self) -> Timestamp<'_> {
pub fn value(&self) -> Timestamp {
match &*self {
Clock::Closed {
start,
@ -127,7 +127,7 @@ impl Clock<'_> {
}
}
fn parse_clock<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&'a str, Clock<'_>, E> {
fn parse_clock<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&str, Clock, E> {
let (input, _) = tag("CLOCK:")(input)?;
let (input, _) = space0(input)?;
let (input, timestamp) = parse_inactive(input)?;

View file

@ -20,7 +20,7 @@ pub struct Cookie<'a> {
}
impl Cookie<'_> {
pub(crate) fn parse(input: &str) -> Option<(&str, Cookie<'_>)> {
pub(crate) fn parse(input: &str) -> Option<(&str, Cookie)> {
parse_cookie::<()>(input).ok()
}
@ -32,7 +32,7 @@ impl Cookie<'_> {
}
#[inline]
fn parse_cookie<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&'a str, Cookie<'a>, E> {
fn parse_cookie<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&str, Cookie, E> {
let (input, value) = recognize(delimited(
tag("["),
alt((

View file

@ -19,7 +19,7 @@ pub struct Drawer<'a> {
}
impl Drawer<'_> {
pub(crate) fn parse(input: &str) -> Option<(&str, (Drawer<'_>, &str))> {
pub(crate) fn parse(input: &str) -> Option<(&str, (Drawer, &str))> {
parse_drawer::<()>(input).ok()
}
@ -33,7 +33,7 @@ impl Drawer<'_> {
#[inline]
pub fn parse_drawer<'a, E: ParseError<&'a str>>(
input: &'a str,
) -> IResult<&'a str, (Drawer<'a>, &'a str), E> {
) -> IResult<&str, (Drawer, &str), E> {
let (input, name) = delimited(
tag(":"),
take_while1(|c: char| c.is_ascii_alphabetic() || c == '-' || c == '_'),

View file

@ -22,7 +22,7 @@ pub struct DynBlock<'a> {
}
impl DynBlock<'_> {
pub(crate) fn parse(input: &str) -> Option<(&str, (DynBlock<'_>, &str))> {
pub(crate) fn parse(input: &str) -> Option<(&str, (DynBlock, &str))> {
parse_dyn_block::<()>(input).ok()
}
@ -37,7 +37,7 @@ impl DynBlock<'_> {
#[inline]
fn parse_dyn_block<'a, E: ParseError<&'a str>>(
input: &'a str,
) -> IResult<&'a str, (DynBlock<'a>, &'a str), E> {
) -> IResult<&str, (DynBlock, &str), E> {
let (input, _) = tag_no_case("#+BEGIN:")(input)?;
let (input, _) = space1(input)?;
let (input, name) = alpha1(input)?;

View file

@ -19,7 +19,7 @@ pub struct FnDef<'a> {
}
impl FnDef<'_> {
pub(crate) fn parse(input: &str) -> Option<(&str, (FnDef<'_>, &str))> {
pub(crate) fn parse(input: &str) -> Option<(&str, (FnDef, &str))> {
parse_fn_def::<()>(input).ok()
}
@ -31,9 +31,7 @@ impl FnDef<'_> {
}
#[inline]
fn parse_fn_def<'a, E: ParseError<&'a str>>(
input: &'a str,
) -> IResult<&'a str, (FnDef<'a>, &'a str), E> {
fn parse_fn_def<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&str, (FnDef, &str), E> {
let (input, label) = delimited(
tag("[fn:"),
take_while1(|c: char| c.is_ascii_alphanumeric() || c == '-' || c == '_'),

View file

@ -21,7 +21,7 @@ pub struct FnRef<'a> {
}
impl FnRef<'_> {
pub(crate) fn parse(input: &str) -> Option<(&str, FnRef<'_>)> {
pub(crate) fn parse(input: &str) -> Option<(&str, FnRef)> {
parse_fn_ref::<()>(input).ok()
}
@ -34,7 +34,7 @@ impl FnRef<'_> {
}
#[inline]
fn parse_fn_ref<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&'a str, FnRef<'a>, E> {
fn parse_fn_ref<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&str, FnRef, E> {
let (input, _) = tag("[fn:")(input)?;
let (input, label) =
take_while(|c: char| c.is_ascii_alphanumeric() || c == '-' || c == '_')(input)?;
@ -50,7 +50,7 @@ fn parse_fn_ref<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&'a str,
))
}
fn balanced_brackets<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&'a str, &'a str, E> {
fn balanced_brackets<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&str, &str, E> {
let mut pairs = 1;
for i in memchr2_iter(b'[', b']', input.as_bytes()) {
if input.as_bytes()[i] == b'[' {

View file

@ -26,7 +26,7 @@ pub struct InlineCall<'a> {
}
impl InlineCall<'_> {
pub(crate) fn parse(input: &str) -> Option<(&str, InlineCall<'_>)> {
pub(crate) fn parse(input: &str) -> Option<(&str, InlineCall)> {
parse_inline_call::<()>(input).ok()
}
@ -41,9 +41,7 @@ impl InlineCall<'_> {
}
#[inline]
fn parse_inline_call<'a, E: ParseError<&'a str>>(
input: &'a str,
) -> IResult<&'a str, InlineCall<'a>, E> {
fn parse_inline_call<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&str, InlineCall, E> {
let (input, name) = preceded(
tag("call_"),
take_till(|c| c == '[' || c == '\n' || c == '(' || c == ')'),

View file

@ -23,7 +23,7 @@ pub struct InlineSrc<'a> {
}
impl InlineSrc<'_> {
pub(crate) fn parse(input: &str) -> Option<(&str, InlineSrc<'_>)> {
pub(crate) fn parse(input: &str) -> Option<(&str, InlineSrc)> {
parse_inline_src::<()>(input).ok()
}
@ -37,9 +37,7 @@ impl InlineSrc<'_> {
}
#[inline]
fn parse_inline_src<'a, E: ParseError<&'a str>>(
input: &'a str,
) -> IResult<&'a str, InlineSrc<'a>, E> {
fn parse_inline_src<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&str, InlineSrc, E> {
let (input, _) = tag("src_")(input)?;
let (input, lang) =
take_while1(|c: char| !c.is_ascii_whitespace() && c != '[' && c != '{')(input)?;

View file

@ -57,7 +57,7 @@ pub fn parse_keyword(input: &str) -> Option<(&str, (&str, Option<&str>, &str))>
#[inline]
fn parse_keyword_internal<'a, E: ParseError<&'a str>>(
input: &'a str,
) -> IResult<&'a str, (&'a str, Option<&'a str>, &'a str), E> {
) -> IResult<&str, (&str, Option<&str>, &str), E> {
let (input, _) = tag("#+")(input)?;
let (input, key) = take_till(|c: char| c.is_ascii_whitespace() || c == ':' || c == '[')(input)?;
let (input, optional) = opt(delimited(

View file

@ -21,7 +21,7 @@ pub struct Link<'a> {
impl Link<'_> {
#[inline]
pub(crate) fn parse(input: &str) -> Option<(&str, Link<'_>)> {
pub(crate) fn parse(input: &str) -> Option<(&str, Link)> {
parse_link::<()>(input).ok()
}
@ -34,7 +34,7 @@ impl Link<'_> {
}
#[inline]
fn parse_link<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&'a str, Link<'a>, E> {
fn parse_link<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&str, Link, E> {
let (input, path) = delimited(
tag("[["),
take_while(|c: char| c != '<' && c != '>' && c != '\n' && c != ']'),

View file

@ -75,7 +75,7 @@ pub struct ListItem<'a> {
impl ListItem<'_> {
#[inline]
pub(crate) fn parse(text: &str, indent: usize) -> (&str, ListItem<'_>, &str) {
pub(crate) fn parse(text: &str, indent: usize) -> (&str, ListItem, &str) {
debug_assert!(&text[0..indent].trim().is_empty());
let off = &text[indent..].find(' ').unwrap() + 1 + indent;

View file

@ -21,7 +21,7 @@ pub struct Macros<'a> {
}
impl Macros<'_> {
pub(crate) fn parse(input: &str) -> Option<(&str, Macros<'_>)> {
pub(crate) fn parse(input: &str) -> Option<(&str, Macros)> {
parse_macros::<()>(input).ok()
}
@ -34,7 +34,7 @@ impl Macros<'_> {
}
#[inline]
fn parse_macros<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&'a str, Macros<'a>, E> {
fn parse_macros<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&str, Macros, E> {
let (input, _) = tag("{{{")(input)?;
let (input, name) = verify(
take_while1(|c: char| c.is_ascii_alphanumeric() || c == '-' || c == '_'),

View file

@ -20,7 +20,7 @@ pub struct Planning<'a> {
impl Planning<'_> {
#[inline]
pub(crate) fn parse(text: &str) -> Option<(&str, Planning<'_>)> {
pub(crate) fn parse(text: &str) -> Option<(&str, Planning)> {
let (mut deadline, mut scheduled, mut closed) = (None, None, None);
let (mut tail, off) = memchr(b'\n', text.as_bytes())
.map(|i| (text[..i].trim(), i + 1))

View file

@ -16,7 +16,7 @@ pub fn parse_radio_target(input: &str) -> Option<(&str, &str)> {
#[inline]
fn parse_radio_target_internal<'a, E: ParseError<&'a str>>(
input: &'a str,
) -> IResult<&'a str, &'a str, E> {
) -> IResult<&str, &str, E> {
let (input, contents) = delimited(
tag("<<<"),
verify(

View file

@ -10,7 +10,7 @@ pub fn parse_rule(input: &str) -> Option<&str> {
.map(|(input, _)| input)
}
fn parse_rule_internal<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&'a str, (), E> {
fn parse_rule_internal<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&str, (), E> {
let (input, _) = take_while_m_n(5, usize::MAX, |c| c == '-')(input)?;
let (input, _) = eol(input)?;
Ok((input, ()))

View file

@ -19,7 +19,7 @@ pub struct Snippet<'a> {
}
impl Snippet<'_> {
pub(crate) fn parse(input: &str) -> Option<(&str, Snippet<'_>)> {
pub(crate) fn parse(input: &str) -> Option<(&str, Snippet)> {
parse_snippet::<()>(input).ok()
}
@ -32,7 +32,7 @@ impl Snippet<'_> {
}
#[inline]
fn parse_snippet<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&'a str, Snippet<'a>, E> {
fn parse_snippet<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&str, Snippet, E> {
let (input, (name, value)) = delimited(
tag("@@"),
separated_pair(

View file

@ -19,7 +19,7 @@ pub struct Target<'a> {
impl Target<'_> {
#[inline]
pub(crate) fn parse(input: &str) -> Option<(&str, Target<'_>)> {
pub(crate) fn parse(input: &str) -> Option<(&str, Target)> {
parse_target::<()>(input).ok()
}
@ -31,7 +31,7 @@ impl Target<'_> {
}
#[inline]
fn parse_target<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&'a str, Target<'a>, E> {
fn parse_target<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&str, Target, E> {
let (input, target) = delimited(
tag("<<"),
verify(

View file

@ -138,15 +138,15 @@ pub enum Timestamp<'a> {
}
impl Timestamp<'_> {
pub(crate) fn parse_active(input: &str) -> Option<(&str, Timestamp<'_>)> {
pub(crate) fn parse_active(input: &str) -> Option<(&str, Timestamp)> {
parse_active::<()>(input).ok()
}
pub(crate) fn parse_inactive(input: &str) -> Option<(&str, Timestamp<'_>)> {
pub(crate) fn parse_inactive(input: &str) -> Option<(&str, Timestamp)> {
parse_inactive::<()>(input).ok()
}
pub(crate) fn parse_diary(input: &str) -> Option<(&str, Timestamp<'_>)> {
pub(crate) fn parse_diary(input: &str) -> Option<(&str, Timestamp)> {
parse_diary::<()>(input).ok()
}
@ -199,9 +199,7 @@ impl Timestamp<'_> {
}
}
pub fn parse_active<'a, E: ParseError<&'a str>>(
input: &'a str,
) -> IResult<&'a str, Timestamp<'a>, E> {
pub fn parse_active<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&str, Timestamp, E> {
let (input, _) = tag("<")(input)?;
let (input, start) = parse_datetime(input)?;
@ -254,9 +252,7 @@ pub fn parse_active<'a, E: ParseError<&'a str>>(
}
}
pub fn parse_inactive<'a, E: ParseError<&'a str>>(
input: &'a str,
) -> IResult<&'a str, Timestamp<'a>, E> {
pub fn parse_inactive<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&str, Timestamp, E> {
let (input, _) = tag("[")(input)?;
let (input, start) = parse_datetime(input)?;
@ -309,9 +305,7 @@ pub fn parse_inactive<'a, E: ParseError<&'a str>>(
}
}
pub fn parse_diary<'a, E: ParseError<&'a str>>(
input: &'a str,
) -> IResult<&'a str, Timestamp<'a>, E> {
pub fn parse_diary<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&str, Timestamp, E> {
let (input, _) = tag("<%%(")(input)?;
let (input, value) = take_till(|c| c == ')' || c == '>' || c == '\n')(input)?;
let (input, _) = tag(")>")(input)?;
@ -324,7 +318,7 @@ pub fn parse_diary<'a, E: ParseError<&'a str>>(
))
}
fn parse_time<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&'a str, (u8, u8), E> {
fn parse_time<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&str, (u8, u8), E> {
let (input, hour) = map_res(take_while_m_n(1, 2, |c: char| c.is_ascii_digit()), |num| {
u8::from_str_radix(num, 10)
})(input)?;
@ -333,7 +327,7 @@ fn parse_time<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&'a str, (u
Ok((input, (hour, minute)))
}
fn parse_datetime<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&'a str, Datetime<'a>, E> {
fn parse_datetime<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&str, Datetime, E> {
let parse_u8 = |num| u8::from_str_radix(num, 10);
let (input, year) = map_res(take(4usize), |num| u16::from_str_radix(num, 10))(input)?;

View file

@ -185,7 +185,7 @@ fn parse_title<'a, E: ParseError<&'a str>>(
#[inline]
fn parse_properties_drawer<'a, E: ParseError<&'a str>>(
input: &'a str,
) -> IResult<&'a str, HashMap<Cow<'a, str>, Cow<'a, str>>, E> {
) -> IResult<&str, HashMap<Cow<'_, str>, Cow<'_, str>>, E> {
let (input, (drawer, content)) = parse_drawer(input.trim_start())?;
if drawer.name != "PROPERTIES" {
return Err(Err::Error(E::from_error_kind(input, ErrorKind::Tag)));
@ -204,7 +204,7 @@ fn parse_properties_drawer<'a, E: ParseError<&'a str>>(
#[inline]
fn parse_node_property<'a, E: ParseError<&'a str>>(
input: &'a str,
) -> IResult<&'a str, (&'a str, &'a str), E> {
) -> IResult<&str, (&str, &str), E> {
let input = skip_empty_lines(input).trim_start();
let (input, name) = map(delimited(tag(":"), take_until(":"), tag(":")), |s: &str| {
s.trim_end_matches('+')

View file

@ -444,7 +444,7 @@ struct InlinePositions<'a> {
}
impl InlinePositions<'_> {
fn new(bytes: &[u8]) -> InlinePositions<'_> {
fn new(bytes: &[u8]) -> InlinePositions {
InlinePositions {
bytes,
position: 0,
@ -670,7 +670,7 @@ pub fn parse_table<'a, T: ElementArena<'a>>(
}
}
pub fn line<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&'a str, &'a str, E> {
pub fn line<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&str, &str, E> {
if let Some(i) = memchr(b'\n', input.as_bytes()) {
if i > 0 && input.as_bytes()[i - 1] == b'\r' {
Ok((&input[i + 1..], &input[0..i - 1]))
@ -682,7 +682,7 @@ pub fn line<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&'a str, &'a
}
}
pub fn eol<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&'a str, &'a str, E> {
pub fn eol<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&str, &str, E> {
verify(line, |s: &str| s.trim().is_empty())(input)
}
@ -751,7 +751,7 @@ pub fn parse_comment(input: &str) -> Option<(&str, &str)> {
}
}
pub fn take_one_word<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&'a str, &'a str, E> {
pub fn take_one_word<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&str, &str, E> {
take_while1(|c: char| !c.is_ascii_whitespace())(input)
}