diff options
author | The Depressed Milkman <github@tdmm.eu> | 2022-11-07 20:14:46 +0100 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2022-11-16 13:44:19 +0100 |
commit | 33c663172bd472e043f0b453d2d45c50699ff628 (patch) | |
tree | d5fff72a045bcd7fa37038bf95d92dd72cc581eb /src/error.rs | |
parent | 8a7054ef7a7c7a6f1ccd507e6921f69c07abfeec (diff) |
Decrease number of heap allocations, and more
Sent over the course of 2 diffs, no real functionality changes, but a
couple general code improvements. The second email reads:
> string encoding/decoding has been rewritten. The duplicate_elements()
> function no longer allocates like crazy. The try_move() and do_move()
> functions still need work, but have not been touched because they will
> likely be rewritten shortly.
Diffstat (limited to 'src/error.rs')
-rw-r--r-- | src/error.rs | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/error.rs b/src/error.rs index 7df065d..d28a8dc 100644 --- a/src/error.rs +++ b/src/error.rs @@ -2,7 +2,7 @@ use std::{ env, fmt::{self, Display}, io, - string + str, }; pub enum Error { @@ -12,8 +12,9 @@ pub enum Error { DupOutputElems(Vec<String>), IOError(io::Error), Nop, - UTF8Error(string::FromUtf8Error), + UTF8Error(std::str::Utf8Error), SpawnFailed(String, io::Error), + BadDecoding(String), } impl Display for Error { @@ -31,7 +32,8 @@ impl Display for Error { Self::IOError(e) => writeln!(f, "{p}: {e}"), Self::Nop => Ok(()), Self::UTF8Error(e) => writeln!(f, "{p}: {e}"), - Self::SpawnFailed(ed, e) => writeln!(f, "{p}: Failed to spawn editor \"{ed}\": {e}") + Self::SpawnFailed(ed, e) => writeln!(f, "{p}: Failed to spawn editor \"{ed}\": {e}"), + Self::BadDecoding(s) => writeln!(f, "{p}: Decoding the text {s:?} failed!"), } } } @@ -42,8 +44,8 @@ impl From<io::Error> for Error { } } -impl From<string::FromUtf8Error> for Error { - fn from(e: string::FromUtf8Error) -> Self { +impl From<str::Utf8Error> for Error { + fn from(e: str::Utf8Error) -> Self { Self::UTF8Error(e) } } |