feat(tvix/nix-compat): add conversion for ParseError to owned version

This error type is a bit less annoying to use in other errors, as it
doesn't hang onto bytes from the input.

Change-Id: I4b969717d443f5e04dd2086baeb946a98c4f9d7c
Reviewed-on: https://cl.tvl.fyi/c/depot/+/13206
Reviewed-by: Brian Olsen <me@griff.name>
Tested-by: BuildkiteCI
This commit is contained in:
Florian Klink 2025-03-02 14:52:23 +07:00 committed by flokli
parent 8347bd20b0
commit 0002a5163f

View file

@ -27,6 +27,20 @@ pub enum Error<I> {
Validation(super::DerivationError),
}
/// Convenience conversion of borring Error to an owned counterpart.
impl From<Error<&[u8]>> for Error<Vec<u8>> {
fn from(value: Error<&[u8]>) -> Self {
match value {
Error::Parser(nom_error) => Error::Parser(NomError {
input: nom_error.input.to_vec(),
code: nom_error.code,
}),
Error::Incomplete => Error::Incomplete,
Error::Validation(e) => Error::Validation(e),
}
}
}
pub(crate) fn parse(i: &[u8]) -> Result<Derivation, Error<&[u8]>> {
match all_consuming(parse_derivation).parse(i) {
Ok((rest, derivation)) => {