use std::collections::HashMap;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Filter {
pub name: String,
pub target: FilterTarget,
pub params: Params,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum FilterTarget {
Video,
Audio,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct Params(HashMap<String, ParamValue>);
impl Params {
pub fn new() -> Self {
Self(HashMap::new())
}
#[must_use]
pub fn set(mut self, key: impl Into<String>, val: impl Into<ParamValue>) -> Self {
self.0.insert(key.into(), val.into());
self
}
pub fn get(&self, key: &str) -> Option<&ParamValue> {
self.0.get(key)
}
pub fn iter(&self) -> impl Iterator<Item = (&str, &ParamValue)> {
self.0.iter().map(|(k, v)| (k.as_str(), v))
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ParamValue {
Int(i64),
Float(f64),
Str(String),
Bool(bool),
}
impl From<i64> for ParamValue {
fn from(v: i64) -> Self {
Self::Int(v)
}
}
impl From<f64> for ParamValue {
fn from(v: f64) -> Self {
Self::Float(v)
}
}
impl From<String> for ParamValue {
fn from(v: String) -> Self {
Self::Str(v)
}
}
impl From<&str> for ParamValue {
fn from(v: &str) -> Self {
Self::Str(v.to_string())
}
}
impl From<bool> for ParamValue {
fn from(v: bool) -> Self {
Self::Bool(v)
}
}