]> Untitled Git - bdk/commitdiff
fix(file_store): rm lifetime from `FileError`
author志宇 <hello@evanlinjin.me>
Thu, 25 Jan 2024 15:39:59 +0000 (00:39 +0900)
committer志宇 <hello@evanlinjin.me>
Thu, 25 Jan 2024 16:13:00 +0000 (01:13 +0900)
The lifetime on the error needed to be the same as the input magic bytes
which was annoying.

crates/file_store/src/lib.rs
crates/file_store/src/store.rs

index de1c73adc32d3ebc15eceb143faaa50673c991f4..7c943ca2006aef624747b42dc7428db36bb4cc9f 100644 (file)
@@ -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<u8>, expected: &'a [u8] },
+    InvalidMagicBytes { got: Vec<u8>, expected: Vec<u8> },
 }
 
-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<io::Error> for FileError<'a> {
+impl From<io::Error> 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 {}
index f24a3e6096f5730794a6520d42680d7d75153eb7..c629d914a97389354aaeee642b4f04beaeaf7a33 100644 (file)
@@ -94,7 +94,7 @@ where
         if magic_buf != magic {
             return Err(FileError::InvalidMagicBytes {
                 got: magic_buf,
-                expected: magic,
+                expected: magic.to_vec(),
             });
         }