use crate::{Framerate, TimecodeParseError};
use std::convert::TryFrom;
use std::fmt::Debug;
pub type PremiereTicksSourceResult = Result<i64, TimecodeParseError>;
pub trait PremiereTicksSource: Debug {
fn to_ticks(&self, rate: Framerate) -> PremiereTicksSourceResult;
}
impl<T> PremiereTicksSource for &T
where
T: PremiereTicksSource,
{
fn to_ticks(&self, rate: Framerate) -> PremiereTicksSourceResult {
(*self).to_ticks(rate)
}
}
impl PremiereTicksSource for &dyn PremiereTicksSource {
fn to_ticks(&self, rate: Framerate) -> PremiereTicksSourceResult {
(*self).to_ticks(rate)
}
}
impl PremiereTicksSource for i64 {
fn to_ticks(&self, _: Framerate) -> PremiereTicksSourceResult {
Ok(*self)
}
}
impl PremiereTicksSource for u64 {
fn to_ticks(&self, _: Framerate) -> PremiereTicksSourceResult {
let i64_val = match i64::try_from(*self) {
Ok(converted) => converted,
Err(err) => {
return Err(TimecodeParseError::Conversion(format!(
"error converting u64 to i64 : {}",
err
)))
}
};
Ok(i64_val)
}
}