From 94089fb22c6d5e7c47e98f49f63e7689c83b523a Mon Sep 17 00:00:00 2001 From: Chris Tam Date: Sun, 11 Feb 2024 22:36:22 -0500 Subject: [PATCH 1/3] Expose the fields of Error as public --- src/error.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/error.rs b/src/error.rs index 26a1ed63..649246b6 100644 --- a/src/error.rs +++ b/src/error.rs @@ -155,11 +155,11 @@ impl PartialEq for ErrorType { #[derive(Debug, PartialEq)] pub struct Error { /// Byte index it was encountered at - index: usize, + pub index: usize, /// Current character - character: Option, + pub character: Option, /// Type of error - error: ErrorType, + pub error: ErrorType, } impl Error { From 69d1cd8e897fbf0be77431a6cb43485a4824c394 Mon Sep 17 00:00:00 2001 From: Chris Tam Date: Sat, 6 Apr 2024 10:08:42 -0400 Subject: [PATCH 2/3] Implement accessor functions instead of pub --- src/error.rs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/error.rs b/src/error.rs index 649246b6..334604a9 100644 --- a/src/error.rs +++ b/src/error.rs @@ -92,7 +92,7 @@ pub enum ErrorType { Io(std::io::Error), } -#[derive(Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq)] pub enum InternalError { TapeError, } @@ -155,11 +155,11 @@ impl PartialEq for ErrorType { #[derive(Debug, PartialEq)] pub struct Error { /// Byte index it was encountered at - pub index: usize, + index: usize, /// Current character - pub character: Option, + character: Option, /// Type of error - pub error: ErrorType, + error: ErrorType, } impl Error { @@ -183,6 +183,21 @@ impl Error { error: t, } } + + /// Returns the byte index the error occurred at. + pub fn index(&self) -> usize { + self.index + } + + /// Returns the current character the error occurred at. + pub fn character(&self) -> Option { + self.character + } + + /// Returns the type of error that occurred. + pub fn error(&self) -> &ErrorType { + &self.error + } } impl std::error::Error for Error {} From d146459c8cbd78576195a6e4fc4f620ed2f76a02 Mon Sep 17 00:00:00 2001 From: Christopher Tam Date: Mon, 15 Apr 2024 07:30:12 -0400 Subject: [PATCH 3/3] Address clippy lints --- src/error.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/error.rs b/src/error.rs index 334604a9..cbf3ff61 100644 --- a/src/error.rs +++ b/src/error.rs @@ -185,16 +185,19 @@ impl Error { } /// Returns the byte index the error occurred at. + #[must_use] pub fn index(&self) -> usize { self.index } /// Returns the current character the error occurred at. + #[must_use] pub fn character(&self) -> Option { self.character } /// Returns the type of error that occurred. + #[must_use] pub fn error(&self) -> &ErrorType { &self.error }