Skip to content

Rust typechecker getting in the way #519

Closed Answered by zesterer
ararunaufc asked this question in Q&A
Discussion options

You must be logged in to vote

So, you have two options here:

  1. Change all of the justs to accept strings, like so:
just(b"\r\n").or(just(b"\n")).or(just(b"\r")).or(just(b"\x0C"))

Because b"..." produces an array, this will compile down to exactly the same thing as if you'd just used single characters ([u8; 1] vs u8).

  1. change the output type of a parsing using .map(...), .ignored(), .to(...), etc.
just(b"\r\n").ignored()
    .or(just(b'\n').ignored())
    .or(just(b'\r').ignored())
    .or(just(b'\x0C').ignored())

or

just(b"\r\n")
    .or(just(b'\n').to(b""))
    .or(just(b'\r').to(b""))
    .or(just(b'\x0C').to(b""))

I'd personally go for option (1) simply because it's shorter, but it's obviously your call. All optio…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@ararunaufc
Comment options

Answer selected by ararunaufc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants