ya_md5/
md5_error.rs

1use thiserror::Error;
2
3/// The error of a [Md5Hasher](crate::Md5Hasher) operation.
4#[derive(Error, Debug)]
5pub enum Md5Error {
6    /// Error while doing [read](std::io::Read::read) from an input.
7    #[error("Error reading input: {0}")]
8    ReadError(std::io::Error),
9    /// Other I/O errors.
10    /// While the [Md5Hasher](crate::Md5Hasher) don't use this error, it allows to create ergonomic
11    /// functions for hashing a [std::io::Read] object.
12    /// ```
13    /// use std::fs::File;
14    /// use std::io::prelude::*;
15    /// use ya_md5::Md5Hasher;
16    /// use ya_md5::Hash;
17    /// use ya_md5::Md5Error;
18    ///
19    /// fn hash_file() -> Result<Hash, Md5Error> {
20    ///     std::fs::write("foo.txt", b"hello world")?;
21    ///     let hash = {
22    ///         let mut file = File::open("foo.txt")?;
23    ///         Md5Hasher::hash(&mut file)?
24    ///     };
25    ///     std::fs::remove_file("foo.txt")?;
26    ///     Ok(hash)
27    /// }
28    ///
29    /// ```
30    #[error("Unexpected I/O error: {0}")]
31    IOError(#[from] std::io::Error),
32}