From 5611c9e42adb4106f48039e19ab0797b266c7fff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BF=97=E5=AE=87?= Date: Fri, 26 Jan 2024 00:39:59 +0900 Subject: [PATCH] fix(file_store): rm lifetime from `FileError` The lifetime on the error needed to be the same as the input magic bytes which was annoying. --- crates/file_store/src/lib.rs | 10 +++++----- crates/file_store/src/store.rs | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/file_store/src/lib.rs b/crates/file_store/src/lib.rs index de1c73ad..7c943ca2 100644 --- a/crates/file_store/src/lib.rs +++ b/crates/file_store/src/lib.rs @@ -13,14 +13,14 @@ pub(crate) fn bincode_options() -> impl bincode::Options { /// Error that occurs due to problems encountered with the file. #[derive(Debug)] -pub enum FileError<'a> { +pub enum FileError { /// IO error, this may mean that the file is too short. Io(io::Error), /// Magic bytes do not match what is expected. - InvalidMagicBytes { got: Vec, expected: &'a [u8] }, + InvalidMagicBytes { got: Vec, expected: Vec }, } -impl<'a> core::fmt::Display for FileError<'a> { +impl core::fmt::Display for FileError { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match self { Self::Io(e) => write!(f, "io error trying to read file: {}", e), @@ -33,10 +33,10 @@ impl<'a> core::fmt::Display for FileError<'a> { } } -impl<'a> From for FileError<'a> { +impl From for FileError { fn from(value: io::Error) -> Self { Self::Io(value) } } -impl<'a> std::error::Error for FileError<'a> {} +impl std::error::Error for FileError {} diff --git a/crates/file_store/src/store.rs b/crates/file_store/src/store.rs index f24a3e60..c629d914 100644 --- a/crates/file_store/src/store.rs +++ b/crates/file_store/src/store.rs @@ -94,7 +94,7 @@ where if magic_buf != magic { return Err(FileError::InvalidMagicBytes { got: magic_buf, - expected: magic, + expected: magic.to_vec(), }); }