qbt-clean 0.120.0

Automated rules-based cleaning of qBittorrent torrents.
#[derive(Debug,serde::Deserialize)]
#[serde(rename_all="kebab-case")]
pub enum Cmp<T> {
	Ge(T),
	Gt(T),
	Le(T),
	Lt(T),
}

impl<T: PartialOrd> Cmp<T> {
	pub fn matches(&self, that: &T) -> bool {
		match self {
			Cmp::Ge(v) => that >= v,
			Cmp::Gt(v) => that > v,
			Cmp::Le(v) => that <= v,
			Cmp::Lt(v) => that < v,
		}
	}
}

impl<
	'd,
	T,
	S: Into<T> + serde::Deserialize<'d>,
> serde_with::DeserializeAs<'d, Cmp<T>> for Cmp<S> {
	fn deserialize_as<D: serde::Deserializer<'d>>(d: D) -> Result<Cmp<T>, D::Error> {
		let v = <Cmp::<S> as serde::Deserialize>::deserialize(d)?;
		Ok(match v {
			Cmp::Ge(v) => Cmp::Ge(v.into()),
			Cmp::Gt(v) => Cmp::Gt(v.into()),
			Cmp::Le(v) => Cmp::Le(v.into()),
			Cmp::Lt(v) => Cmp::Lt(v.into()),
		})
	}
}