use crate::config::Parse;
#[derive(Debug, Clone)]
#[non_exhaustive]
pub enum S3CopyIfNotExists {
Header(String, String),
}
impl std::fmt::Display for S3CopyIfNotExists {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Header(k, v) => write!(f, "header: {}: {}", k, v),
}
}
}
impl S3CopyIfNotExists {
fn from_str(s: &str) -> Option<Self> {
let (variant, value) = s.split_once(':')?;
match variant.trim() {
"header" => {
let (k, v) = value.split_once(':')?;
Some(Self::Header(k.trim().to_string(), v.trim().to_string()))
}
_ => None,
}
}
}
impl Parse for S3CopyIfNotExists {
fn parse(v: &str) -> crate::Result<Self> {
Self::from_str(v).ok_or_else(|| crate::Error::Generic {
store: "Config",
source: format!("Failed to parse \"{v}\" as S3CopyIfNotExists").into(),
})
}
}