1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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.to_string()
)))
}
};
Ok(i64_val)
}
}