Repository: Marwes/combine (language: rust)

Issue:
take_until_bytes() and partial parsing
I'm attempting to write a parser that searches for the start of a sync pattern in a byte stream.  If the pattern doesn't exist, I'd like to remove the unmatched prefix from the input.

```rust
pub fn parser5() {

    let sync = [1u8, 2, 3, 4, 5];
    let data_in = [9, 9, 1, 2, 3, 4];

    {
        let mut din          = combine::stream::PartialStream(&data_in[..]);
        let mut pos          = 0;
        let mut prefix_range = take_until_range(&sync[..]);

        let r  = prefix_range.parse_with_state(&mut din, &mut pos);
        dbg!(r);
        assert_eq!(pos, 2);
    }
    {
        let mut din          = combine::stream::PartialStream(&data_in[..]);
        let mut pos          = 0;
        let mut prefix_bytes = take_until_bytes(&sync[..]);

        let r  = prefix_bytes.parse_with_state(&mut din, &mut pos);
        dbg!(r);
        assert_eq!(pos, 2);
    }
}

```

I initially attempted using the `take_until_bytes()` function, but this function expects a `PartialState = ()`.  This is shown by the following compile error:

```
215 |         let r  = prefix_bytes.parse_with_state(&mut din, &mut pos);
    |                                                          ^^^^^^^^ expected `()`, found integer
    |
    = note: expected mutable reference `&mut ()`
               found mutable reference `&mut {integer}`

For more information about this error, try `rustc --explain E0308`.
error: could not compile `parser-tests` due to previous error
```

Internally, the `take_until_bytes()` function utilizes the `take_fn()` that should return a `TakeRange::NotFound( amount to remove)`, but I can't get this to type check.

Questions:
- Is this the idiom I should be using?
- Should `take_until_bytes()` support partial parsing?




Discussion / hints:

Fix patch:
diff --git a/src/parser/byte.rs b/src/parser/byte.rs
index b28d3626..c70769d8 100644
--- a/src/parser/byte.rs
+++ b/src/parser/byte.rs
@@ -311,6 +311,7 @@ macro_rules! take_until {
         parser!{
             #[derive(Clone)]
             pub struct $type_name;
+            type PartialState = usize;
             $(#[$attr])*
             pub fn $func_name[Input]($($param : u8),*)(Input) -> Input::Range
                 where [
@@ -389,6 +390,7 @@ take_until! {
 }
 
 parser! {
+type PartialState = usize;
 /// Zero-copy parser which reads a range of 0 or more tokens until `needle` is found.
 ///
 /// If `a`, 'b' or `c` is not found, the parser will return an error.


Test patch: