Impl FromStr for Algorithm enum
This commit is contained in:
parent
05bec9ae2f
commit
d303eb0390
@ -1,6 +1,6 @@
|
|||||||
use {
|
use {
|
||||||
crate::Error,
|
crate::Error,
|
||||||
std::io::{Read, Write},
|
std::{io::{Read, Write}, str::FromStr},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
@ -11,6 +11,20 @@ pub enum Algorithm {
|
|||||||
Skip,
|
Skip,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl FromStr for Algorithm {
|
||||||
|
type Err = Error;
|
||||||
|
|
||||||
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
|
match s {
|
||||||
|
"md5" | "Md5" => Ok(Self::Md5),
|
||||||
|
"sha1" | "Sha1" => Ok(Self::Sha1),
|
||||||
|
"sha256" | "Sha256" => Ok(Self::Sha256),
|
||||||
|
"skip" | "Skip" => Ok(Self::Skip),
|
||||||
|
_ => Err(Error::InvalidAlgorithm),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Optional checksumming for individual files
|
/// Optional checksumming for individual files
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Checksum {
|
pub enum Checksum {
|
||||||
|
@ -9,6 +9,7 @@ pub enum Error {
|
|||||||
Utf8(FromUtf8Error),
|
Utf8(FromUtf8Error),
|
||||||
Slice(TryFromSliceError),
|
Slice(TryFromSliceError),
|
||||||
InvalidChecksum,
|
InvalidChecksum,
|
||||||
|
InvalidAlgorithm,
|
||||||
MissingData,
|
MissingData,
|
||||||
MutexError,
|
MutexError,
|
||||||
NulError,
|
NulError,
|
||||||
@ -25,6 +26,7 @@ impl fmt::Display for Error {
|
|||||||
Self::Utf8(e) => write!(f, "{e}"),
|
Self::Utf8(e) => write!(f, "{e}"),
|
||||||
Self::Slice(e) => write!(f, "{e}"),
|
Self::Slice(e) => write!(f, "{e}"),
|
||||||
Self::Io(e) => write!(f, "{e}"),
|
Self::Io(e) => write!(f, "{e}"),
|
||||||
|
Self::InvalidAlgorithm => write!(f, "invalid algorithm"),
|
||||||
Self::InvalidChecksum => write!(f, "invalid checksum"),
|
Self::InvalidChecksum => write!(f, "invalid checksum"),
|
||||||
Self::MissingData => write!(f, "missing data"),
|
Self::MissingData => write!(f, "missing data"),
|
||||||
Self::MutexError => write!(f, "mutex error"),
|
Self::MutexError => write!(f, "mutex error"),
|
||||||
|
Loading…
Reference in New Issue
Block a user