1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
use clap::ValueEnum;
use std::{
fmt::{Display, Formatter},
str::FromStr,
};
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum, Debug)]
#[clap(rename_all = "lower")]
pub enum InputConvertFormat {
CSV,
ShExC,
ShExJ,
Turtle,
}
impl FromStr for InputConvertFormat {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_lowercase().as_str() {
"csv" => Ok(InputConvertFormat::CSV),
"shexc" => Ok(InputConvertFormat::ShExC),
"shexj" => Ok(InputConvertFormat::ShExJ),
"turtle" => Ok(InputConvertFormat::Turtle),
_ => Err(format!("Unsupported input convert format {s}")),
}
}
}
impl Display for InputConvertFormat {
fn fmt(&self, dest: &mut Formatter<'_>) -> Result<(), std::fmt::Error> {
match self {
InputConvertFormat::CSV => write!(dest, "csv"),
InputConvertFormat::ShExC => write!(dest, "shexc"),
InputConvertFormat::ShExJ => write!(dest, "shexj"),
InputConvertFormat::Turtle => write!(dest, "turtle"),
}
}
}
#[cfg(test)]
mod tests {
use super::InputConvertFormat;
use std::str::FromStr;
#[test]
fn test_from_str() {
assert_eq!(
InputConvertFormat::from_str("CSV").unwrap(),
InputConvertFormat::CSV
)
}
}
|