Struct zalgo_codec_common::Error
source · pub struct Error { /* private fields */ }
Expand description
The error returned by zalgo_encode
, ZalgoString::new
, and zalgo_wrap_python
if they encounter a byte they can not encode.
Only implements the Error
trait if the std
feature is enabled.
Implementations§
source§impl Error
impl Error
sourcepub const fn line(&self) -> usize
pub const fn line(&self) -> usize
Returns the 1-indexed line number of the line on which the unencodable byte occured.
§Examples
assert_eq!(zalgo_encode("❤️").map_err(|e| e.line()), Err(1));
assert_eq!(zalgo_encode("a\nb\nc\r\n").map_err(|e| e.line()), Err(3));
sourcepub const fn column(&self) -> usize
pub const fn column(&self) -> usize
Returns the 1-indexed column where the unencodable byte occured. Columns are counted from left to right and the count resets for each new line.
§Example
assert_eq!(zalgo_encode("I ❤️ 🎂").map_err(|e| e.column()), Err(3));
assert_eq!(zalgo_encode("I\n❤️\n🎂").map_err(|e|e.column()), Err(1));
sourcepub const fn char(&self) -> char
pub const fn char(&self) -> char
Returns the unencodable character that caused the error.
This may not match with what you see when you look at the unencoded string in a text editor since some grapheme clusters consist of many unicode characters.
§Examples
assert_eq!(zalgo_encode("CRLF\r\n").map_err(|e| e.char()), Err('\r'));
The ❤️ emoji consists of two characters, the heart U+2764
and the color variant selector U+FE0F
.
Since the heart is not encodable, that is the place where the error is generated:
assert_eq!(zalgo_encode("❤️").map_err(|e| e.char()), Err('❤'));
The grapheme cluster á
consists of a normal a
and a combining acute accent, U+301
.
The a
can be encoded and the combining acute accent can not, so the error points only to the accent:
assert_eq!(zalgo_encode("á").map_err(|e| e.char()), Err('\u{301}'))
sourcepub const fn index(&self) -> usize
pub const fn index(&self) -> usize
Returns the index of the string where the unencodable character occured.
§Example
assert_eq!(zalgo_encode("ab\ncdë").map_err(|e| e.index()), Err(5));
sourcepub fn backtrace(&self) -> &Backtrace
Available on crate feature std
only.
pub fn backtrace(&self) -> &Backtrace
std
only.Returns a reference to a Backtrace
that was captured when the error was created.
See the documentation of Backtrace::capture
for more information about how to make it
show more information when displayed.
Trait Implementations§
source§impl Error for Error
Available on crate feature std
only.
impl Error for Error
std
only.