[][src]Struct video_timecode::Timecode

pub struct Timecode<T: FrameRate> {
    pub frame_number: u32,
    pub hour: u8,
    pub minute: u8,
    pub second: u8,
    pub frame: u8,
    // some fields omitted
}

Representation of a timecode as a struct, generic over types implementing the trait FrameRate.

Note: Currently the user-facing values are open properties. These may be replaced by getters to facilitate lazy evaluation.

use video_timecode::*;
use std::str::FromStr;

let tc1 = Timecode::<FrameRate24>::new(0, 0, 0, 10).unwrap();
assert_eq!(tc1.frame_number, 10);

let tc2 = Timecode::<FrameRate24>::from_str("00:00:10:00").unwrap();
assert_eq!(tc2.frame_number, 240);

let mut tc3 = Timecode::<FrameRate24>::from(240);
assert_eq!(tc3.hour, 0);
assert_eq!(tc3.minute, 0);
assert_eq!(tc3.second, 10);
assert_eq!(tc3.frame, 0);
assert_eq!(tc3.frame_number, 240);

tc3 += tc1;
assert_eq!(tc3.hour, 0);
assert_eq!(tc3.minute, 0);
assert_eq!(tc3.second, 10);
assert_eq!(tc3.frame, 10);
assert_eq!(tc3.frame_number, 250);

Fields

frame_number: u32

Frame number. The count of frames after 00:00:00:00

hour: u8minute: u8second: u8frame: u8

Methods

impl<T: FrameRate> Timecode<T>[src]

pub fn new(
    hour: u8,
    minute: u8,
    second: u8,
    frame: u8
) -> Result<Timecode<T>, TimecodeError>
[src]

Returns a timecode with the given hour/minute/second/frame fields.

use video_timecode::*;

let timecode = Timecode::<FrameRate24>::new(10, 0, 0, 0).unwrap();
assert_eq!(timecode.frame_number, 864000);

Trait Implementations

impl<T: PartialEq + FrameRate> PartialEq<Timecode<T>> for Timecode<T>[src]

impl<T: Clone + FrameRate> Clone for Timecode<T>[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl<T: FrameRate> From<u32> for Timecode<T>[src]

Create a timecode with the the given frame number.

impl<T: PartialOrd + FrameRate> PartialOrd<Timecode<T>> for Timecode<T>[src]

impl<T: FrameRate> Display for Timecode<T>[src]

impl<T: FrameRate> Debug for Timecode<T>[src]

impl<T: FrameRate> Sub<u32> for Timecode<T>[src]

Make a new timecode by removing a number of frames to a timecode.

type Output = Self

The resulting type after applying the - operator.

impl<T: FrameRate> Add<u32> for Timecode<T>[src]

Make a new timecode by adding a number of frames to a timecode.

type Output = Self

The resulting type after applying the + operator.

impl<T: FrameRate> Add<Timecode<T>> for Timecode<T>[src]

Make a new timecode by adding two timecodes together. The result is a timecode where the field frame_number is the sum of the frame numbers of the two added timecodes.

use video_timecode::*;

let tc1 = Timecode::<FrameRate24>::new(0, 0, 20, 0).unwrap();
let tc2 = Timecode::<FrameRate24>::new(0, 0, 10, 0).unwrap();
let tc3 = tc1 + tc2;
assert_eq!(tc3, Timecode::<FrameRate24>::new(0, 0, 30, 0).unwrap());

Adding Timecodes of different frame rates

Adding timecodes of different framerates together is not supported.

Since adding Timecodes of different frame rates together normally does not make any sense, it is better that the programmer has to mark this, by explicitly adding the number of frames.

This example deliberately fails to compile
use video_timecode::*;

let tc1 = Timecode::<FrameRate2997>::new(0, 0, 0, 0).unwrap();
let tc2 = Timecode::<FrameRate24>::new(0, 0, 10, 0).unwrap();
let tc3 = tc1 + tc2;

Timecode roll-over

The timecode (including the frame_number field) will roll over when the timecode reaches 24 hours.

use video_timecode::*;

let tc1 = Timecode::<FrameRate24>::new(23, 59, 30, 0).unwrap();
let tc2 = Timecode::<FrameRate24>::new(0, 1, 0, 0).unwrap();
let tc3 = tc1 + tc2;
assert_eq!(tc3, Timecode::<FrameRate24>::new(0, 0, 30, 0).unwrap());

type Output = Timecode<T>

The resulting type after applying the + operator.

impl<T: FrameRate> AddAssign<u32> for Timecode<T>[src]

Add a number of frames to a timecode.

impl<T: FrameRate> AddAssign<Timecode<T>> for Timecode<T>[src]

Add one timecode to another, of the same frame rate. The first timecode will have a frame_number that's the sum of the frame numbers of the two timecodes.

use video_timecode::*;

let mut tc1 = Timecode::<FrameRate24>::new(0, 0, 10, 0).unwrap();
let tc2 = Timecode::<FrameRate24>::new(0, 0, 10, 0).unwrap();
tc1 += tc2;

assert_eq!(tc1, Timecode::<FrameRate24>::new(0, 0, 20, 0).unwrap());

impl<T: FrameRate> SubAssign<u32> for Timecode<T>[src]

Remove a number of frames from a timecode.

impl<T: FrameRate + Clone + PartialOrd> Step for Timecode<T>[src]

Iterate over timecodes in steps.

use video_timecode::*;

assert_eq!(
    (Timecode::<FrameRate24>::new(00, 0, 59, 22).unwrap()
        ..Timecode::<FrameRate24>::new(00, 1, 0, 2).unwrap())
        .collect::<Vec<Timecode<FrameRate24>>>(),
    vec![
        Timecode::<FrameRate24>::new(00, 0, 59, 22).unwrap(),
        Timecode::<FrameRate24>::new(00, 0, 59, 23).unwrap(),
        Timecode::<FrameRate24>::new(00, 1, 0, 0).unwrap(),
        Timecode::<FrameRate24>::new(00, 1, 0, 1).unwrap(),
    ]
);

impl<T: FrameRate> FromStr for Timecode<T>[src]

Parse a string into a timecode.

Colon separator is alright for all types.

use video_timecode::*;
use std::str::FromStr;

let tc1 = Timecode::<FrameRate24>::from_str("00:00:10:00").unwrap();
assert_eq!(tc1.frame_number, 240);

let tc2 = Timecode::<FrameRate2997>::from_str("00:00:10:00").unwrap();
assert_eq!(tc2.frame_number, 300);

For frame rates with drop frame, the following formats are also allowed:

  • 00:00:00;00
  • 00;00;00;00
  • 00.00.00.00
  • 00:00:00.00
use video_timecode::*;
use std::str::FromStr;

let tc1 = Timecode::<FrameRate2997>::from_str("00:00:10;00").unwrap();
assert_eq!(tc1.frame_number, 300);

let tc2 = Timecode::<FrameRate2997>::from_str("00;00;10;00").unwrap();
assert_eq!(tc2.frame_number, 300);

let tc3 = Timecode::<FrameRate2997>::from_str("00:00:10.00").unwrap();
assert_eq!(tc3.frame_number, 300);

let tc4 = Timecode::<FrameRate2997>::from_str("00.00.10.00").unwrap();
assert_eq!(tc4.frame_number, 300);

type Err = TimecodeError

If parsing fails, a timecode error is returned.

If the input format is invalid in some way, the TimecodeErrorKind field of the TimecodeError will be InvalidFormat.

use video_timecode::*;
use video_timecode::TimecodeErrorKind::*;
use std::str::FromStr;

// Semicolon notation only allowed for drop frame frame rates.
match Timecode::<FrameRate24>::from_str("00:00:10;00") {
    Err(TimecodeError { kind: InvalidFormat }) => {}
    _ => panic!()
}

If the timecode is not valid for the given frame rate, it will be InvalidTimecode.

use video_timecode::*;
use video_timecode::TimecodeErrorKind::*;
use std::str::FromStr;

// This is a dropped frame.
match Timecode::<FrameRate2997>::from_str("00:01:00;00") {
    Err(TimecodeError { kind: InvalidTimecode }) => {}
    _ => panic!()
}

Auto Trait Implementations

impl<T> Send for Timecode<T> where
    T: Send

impl<T> Sync for Timecode<T> where
    T: Sync

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]