Skip to content

Fix Default implementation for TimeBase #364

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions symphonia-core/src/units.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

use std::fmt;

/// A `TimeStamp` represents an instantenous instant in time since the start of a stream. One
/// A `TimeStamp` represents an instantaneous instant in time since the start of a stream. One
/// `TimeStamp` "tick" is equivalent to the stream's `TimeBase` in seconds.
pub type TimeStamp = u64;

Expand Down Expand Up @@ -135,7 +135,7 @@ impl From<Time> for std::time::Duration {
///
/// In other words, a `TimeBase` is the length in seconds of one tick of a `TimeStamp` or
/// `Duration`.
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct TimeBase {
/// The numerator.
pub numer: u32,
Expand Down Expand Up @@ -234,6 +234,17 @@ impl From<TimeBase> for f64 {
}
}

impl Default for TimeBase {
fn default() -> Self {
// Make sure the default returns an illegal value
// with a TimeBase of 0.
Self {
numer: 1,
denom: 1,
}
}
}

impl fmt::Display for TimeBase {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}/{}", self.numer, self.denom)
Expand Down