Split InputModify and ParseResultModify into more specialized traits
m4rw3r opened this issue · 0 comments
m4rw3r commented
Problem
internal::InputModify
and internal::ParseResultModify
contain too many methods, making it hard to see what a part is actually doing with the Input
and ParseResult
types.
Proposed solution
Remove ParseResultModify
and InputModify
and replace with the following traits:
Note: ParseResultModify::modify
does not need any corresponding trait, it is unused.
- Replace all uses of
InputModify::modify
withbuffer()
+replace(buffer)
.
IntoInner
trait
pub trait IntoInner {
type Inner;
fn into_inner() -> Self::Inner;
}
Input -> (InputState, &[I])
ParseResult -> State
ParseResultChain
for ParseResult
Is this really useful? It is used in two spots in combinators.rs
.
pub trait ParseResultChain {
fn chain<F, T, E>(self, F) -> ParseResult<'a, Self::Input, T, E>
where F: FnOnce(State<'a, Self::Input, Self::Data, Self::Error>)
...;
}
InputClone
pub trait InputClone {
fn clone_input(&self) -> Self;
}
InputBuffer
pub trait InputBuffer<'a> {
fn buffer(&self) -> &'a [Self::Type]
where <Self as InputModify<'a>>::Type: 'a;
fn replace(self, &'a [Self::Type]) -> Self
where <Self as InputModify<'a>>::Type: 'a;
fn is_last_slice(&self) -> bool;
}
replace
is never used without buffer
(except for in one case combined with parse
), and same goes for is_last_slice
.
InputIncomplete
pub trait InputIncomplete {
fn incomplete<T, E>(self, usize) -> ParseResult<'a, Self::Type, T, E>;
}