Using Cow<'a, str> as return type #812
Answered
by
epage
decipher3114
asked this question in
Q&A
-
Input Typepub type StatefulInput<'input, 'state> = Stateful<LocatingSlice<&'input str>, ParseState<'state>>; Literal Type#[derive(Debug, Clone, PartialEq)]
pub enum Literal<'a> {
String(Cow<'a, str>),
Integer(i64),
Decimal(f64),
Boolean(bool),
}
impl<'a> Literal<'a> {
pub(crate) fn parse(input: &mut StatefulInput) -> ModalResult<Literal<'a>> {
alt((
string::parse.map(Literal::String), // Error here
decimal::parse.map(Literal::Decimal),
integer::parse.map(Literal::Integer),
boolean::parse.map(Literal::Boolean),
))
.parse_next(input)
}
} Error
|
Beta Was this translation helpful? Give feedback.
Answered by
epage
Aug 19, 2025
Replies: 2 comments 1 reply
-
Just observed that whenever the |
Beta Was this translation helpful? Give feedback.
0 replies
-
It should at least be #[derive(Debug, Clone, PartialEq)]
pub enum Literal<'a> {
String(Cow<'a, str>),
Integer(i64),
Decimal(f64),
Boolean(bool),
}
impl<'a> Literal<'a> {
pub(crate) fn parse(input: &mut StatefulInput<'a, '_>) -> ModalResult<Literal<'a>> {
alt((
string::parse.map(Literal::String), // Error here
decimal::parse.map(Literal::Decimal),
integer::parse.map(Literal::Integer),
boolean::parse.map(Literal::Boolean),
))
.parse_next(input)
}
} The input's lifetime needs to typed to the If that is still causing an error like this, I'll likely need a reproduction case to help further. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
btw you most likely need something like
I've generally found that once lifetimes are involved, you have to explicitly state your mutable-ref lifetime.