Use static strings for CustomError.
All checks were successful
rustfmt Build rustfmt has succeeded
rust-test Build rust-test has succeeded
rust-build Build rust-build has succeeded
rust-foreign-document-test Build rust-foreign-document-test has succeeded

This resulted in a 20% speedup.
This commit is contained in:
Tom Alexander 2023-09-29 11:26:23 -04:00
parent 90433aa55f
commit 1b7326eafe
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -4,10 +4,9 @@ use nom::IResult;
pub(crate) type Res<T, U> = IResult<T, U, CustomError<T>>; pub(crate) type Res<T, U> = IResult<T, U, CustomError<T>>;
// TODO: MyError probably shouldn't be based on the same type as the input type since it's used exclusively with static strings right now.
#[derive(Debug)] #[derive(Debug)]
pub enum CustomError<I> { pub enum CustomError<I> {
MyError(MyError<I>), MyError(MyError<&'static str>),
Nom(I, ErrorKind), Nom(I, ErrorKind),
IO(std::io::Error), IO(std::io::Error),
} }
@ -31,3 +30,9 @@ impl<I> From<std::io::Error> for CustomError<I> {
CustomError::IO(value) CustomError::IO(value)
} }
} }
impl<I> From<&'static str> for CustomError<I> {
fn from(value: &'static str) -> Self {
CustomError::MyError(MyError(value))
}
}