Merge bitcoindevkit/bdk#1299: fix(file_store): rm lifetime from FileError

5611c9e42adb4106f48039e19ab0797b266c7fff fix(file_store): rm lifetime from `FileError` (志宇)

Pull request description:

  ### Description

  The lifetime on the error needed to be the same as the input magic bytes which was annoying.

  ### Changelog notice

  Fixed
  * Remove `bdk_file_store::FileError` lifetime.

  ### Checklists

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
  * [x] I ran `cargo fmt` and `cargo clippy` before committing

ACKs for top commit:
  LLFourn:
    ACK 5611c9e42adb4106f48039e19ab0797b266c7fff

Tree-SHA512: 0eca5128c71c9adb10a712d169a2170b8cbb91678f93986957e86b26dbfed3ab19217a136b57328249a13a51cc06e6c424d58683d74a0fa3d29c22af04a95591
This commit is contained in:
志宇 2024-01-29 17:52:00 +09:00
commit 6a03e0f209
No known key found for this signature in database
GPG Key ID: F6345C9837C2BDE8
2 changed files with 6 additions and 6 deletions

View File

@ -13,14 +13,14 @@ pub(crate) fn bincode_options() -> impl bincode::Options {
/// Error that occurs due to problems encountered with the file. /// Error that occurs due to problems encountered with the file.
#[derive(Debug)] #[derive(Debug)]
pub enum FileError<'a> { pub enum FileError {
/// IO error, this may mean that the file is too short. /// IO error, this may mean that the file is too short.
Io(io::Error), Io(io::Error),
/// Magic bytes do not match what is expected. /// 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 { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self { match self {
Self::Io(e) => write!(f, "io error trying to read file: {}", e), 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 { fn from(value: io::Error) -> Self {
Self::Io(value) Self::Io(value)
} }
} }
impl<'a> std::error::Error for FileError<'a> {} impl std::error::Error for FileError {}

View File

@ -94,7 +94,7 @@ where
if magic_buf != magic { if magic_buf != magic {
return Err(FileError::InvalidMagicBytes { return Err(FileError::InvalidMagicBytes {
got: magic_buf, got: magic_buf,
expected: magic, expected: magic.to_vec(),
}); });
} }