Manually implement Debug and make convert_error more generic.
All checks were successful
rust-test Build rust-test has succeeded
rust-build Build rust-build has succeeded

This commit is contained in:
Tom Alexander 2023-08-29 10:58:05 -04:00
parent 288350daef
commit 14b1d0526c
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -11,7 +11,7 @@ use nom::Slice;
use crate::error::CustomError;
use crate::error::MyError;
#[derive(Debug, Copy, Clone)]
#[derive(Copy, Clone)]
pub struct OrgSource<'s> {
full_source: &'s str,
start: usize,
@ -24,6 +24,14 @@ pub struct OrgSource<'s> {
parenthesis_depth: isize, // ()
}
impl<'s> std::fmt::Debug for OrgSource<'s> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_tuple("OrgSource")
.field(&Into::<&str>::into(self))
.finish()
}
}
impl<'s> OrgSource<'s> {
/// Returns a wrapped string that keeps track of values we need for parsing org-mode.
///
@ -302,7 +310,9 @@ impl<'s> InputTakeAtPosition for OrgSource<'s> {
}
}
pub fn convert_error(err: nom::Err<CustomError<OrgSource<'_>>>) -> nom::Err<CustomError<&str>> {
pub fn convert_error<'a, I: Into<CustomError<&'a str>>>(
err: nom::Err<I>,
) -> nom::Err<CustomError<&'a str>> {
match err {
nom::Err::Incomplete(needed) => nom::Err::Incomplete(needed),
nom::Err::Error(err) => nom::Err::Error(err.into()),