use crate::Error;
use core::fmt;
use core::fmt::Display;
use core::fmt::Formatter;
use std::str::FromStr;
#[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum ObjectType {
Blob,
Tree,
Commit,
Tag,
}
impl Display for ObjectType {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(
f,
"{}",
match self {
ObjectType::Blob => "blob",
ObjectType::Tree => "tree",
ObjectType::Commit => "commit",
ObjectType::Tag => "tag",
}
)
}
}
impl FromStr for ObjectType {
type Err = Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"blob" => Ok(ObjectType::Blob),
"tree" => Ok(ObjectType::Tree),
"commit" => Ok(ObjectType::Commit),
"tag" => Ok(ObjectType::Tag),
_ => Err(Error::UnknownObjectType(s.to_owned())),
}
}
}