From 1b7326eafe155f80c5e49fe4a8407c869a4d0ee9 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Fri, 29 Sep 2023 11:26:23 -0400 Subject: [PATCH] Use static strings for CustomError. This resulted in a 20% speedup. --- src/error/error.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/error/error.rs b/src/error/error.rs index d6a882c1..8032a25c 100644 --- a/src/error/error.rs +++ b/src/error/error.rs @@ -4,10 +4,9 @@ use nom::IResult; pub(crate) type Res = IResult>; -// 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)] pub enum CustomError { - MyError(MyError), + MyError(MyError<&'static str>), Nom(I, ErrorKind), IO(std::io::Error), } @@ -31,3 +30,9 @@ impl From for CustomError { CustomError::IO(value) } } + +impl From<&'static str> for CustomError { + fn from(value: &'static str) -> Self { + CustomError::MyError(MyError(value)) + } +}