use std::collections::HashMap;
use crate::ContentType;
#[derive(Debug, Clone)]
pub struct CodecMetadata {
content_type: ContentType,
data: HashMap<String, String>,
}
impl CodecMetadata {
#[must_use]
pub fn new(content_type: ContentType) -> Self {
Self {
content_type,
data: HashMap::new(),
}
}
#[must_use]
pub const fn content_type(&self) -> &ContentType {
&self.content_type
}
#[must_use]
pub fn get(&self, key: &str) -> Option<&str> {
self.data.get(key).map(String::as_str)
}
pub fn set(&mut self, key: impl Into<String>, value: impl Into<String>) {
self.data.insert(key.into(), value.into());
}
pub fn remove(&mut self, key: &str) -> Option<String> {
self.data.remove(key)
}
#[must_use]
pub fn contains_key(&self, key: &str) -> bool {
self.data.contains_key(key)
}
#[must_use]
pub const fn data(&self) -> &HashMap<String, String> {
&self.data
}
#[must_use]
pub fn len(&self) -> usize {
self.data.len()
}
#[must_use]
pub fn is_empty(&self) -> bool {
self.data.is_empty()
}
}
impl PartialEq for CodecMetadata {
fn eq(&self, other: &Self) -> bool {
self.content_type == other.content_type && self.data == other.data
}
}
impl Eq for CodecMetadata {}
#[cfg(test)]
#[path = "metadata_tests.rs"]
mod tests;