From 33c663172bd472e043f0b453d2d45c50699ff628 Mon Sep 17 00:00:00 2001 From: The Depressed Milkman Date: Mon, 7 Nov 2022 20:14:46 +0100 Subject: 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. --- src/error.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/error.rs') 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), 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 for Error { } } -impl From for Error { - fn from(e: string::FromUtf8Error) -> Self { +impl From for Error { + fn from(e: str::Utf8Error) -> Self { Self::UTF8Error(e) } } -- cgit v1.2.3