pub trait MetadataFields {
fn title(&self) -> &str;
fn author(&self) -> &str;
fn comments(&self) -> &str {
""
}
fn format(&self) -> &str;
fn frame_count(&self) -> Option<usize> {
None
}
fn frame_rate(&self) -> u32 {
50
}
fn duration_seconds(&self) -> Option<f32> {
self.frame_count()
.map(|fc| fc as f32 / self.frame_rate() as f32)
}
fn loop_frame(&self) -> Option<usize> {
None
}
}
pub trait PlaybackMetadata: MetadataFields {}
impl<T: MetadataFields> PlaybackMetadata for T {}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct BasicMetadata {
pub title: String,
pub author: String,
pub comments: String,
pub format: String,
pub frame_count: Option<usize>,
pub frame_rate: u32,
pub loop_frame: Option<usize>,
}
impl MetadataFields for BasicMetadata {
fn title(&self) -> &str {
&self.title
}
fn author(&self) -> &str {
&self.author
}
fn comments(&self) -> &str {
&self.comments
}
fn format(&self) -> &str {
&self.format
}
fn frame_count(&self) -> Option<usize> {
self.frame_count
}
fn frame_rate(&self) -> u32 {
self.frame_rate
}
fn loop_frame(&self) -> Option<usize> {
self.loop_frame
}
}
impl BasicMetadata {
pub fn new() -> Self {
Self {
frame_rate: 50,
..Default::default()
}
}
pub fn with_title_author(title: impl Into<String>, author: impl Into<String>) -> Self {
Self {
title: title.into(),
author: author.into(),
frame_rate: 50,
..Default::default()
}
}
}