Struct video_timecode::Timecode [] [src]

pub struct Timecode<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. The count of frames after 00:00:00:00

Methods

impl<T> Timecode<T>
[src]

[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<FrameRate: Debug> Debug for Timecode<FrameRate>
[src]

[src]

Formats the value using the given formatter.

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

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

[src]

This method tests for !=.

impl<T> FromStr for Timecode<T> where
    T: FrameRate
[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);

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!()
}

[src]

Parses a string s to return a value of this type. Read more

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

[src]

Formats the value using the given formatter. Read more

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

Create a timecode with the the given frame number.

[src]

Performs the conversion.

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

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

The resulting type after applying the + operator.

[src]

Performs the + operation.

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

Add a number of frames to a timecode.

[src]

Performs the += operation.

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

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

The resulting type after applying the - operator.

[src]

Performs the - operation.

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

Remove a number of frames from a timecode.

[src]

Performs the -= operation.

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

Create a timecode with the the given frame number.

[src]

Performs the conversion.

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

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

The resulting type after applying the + operator.

[src]

Performs the + operation.

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

Add a number of frames to a timecode.

[src]

Performs the += operation.

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

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

The resulting type after applying the - operator.

[src]

Performs the - operation.

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

Remove a number of frames from a timecode.

[src]

Performs the -= operation.

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

Create a timecode with the the given frame number.

[src]

Performs the conversion.

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

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

The resulting type after applying the + operator.

[src]

Performs the + operation.

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

Add a number of frames to a timecode.

[src]

Performs the += operation.

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

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

The resulting type after applying the - operator.

[src]

Performs the - operation.

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

Remove a number of frames from a timecode.

[src]

Performs the -= operation.

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

Create a timecode with the the given frame number.

[src]

Performs the conversion.

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

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

The resulting type after applying the + operator.

[src]

Performs the + operation.

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

Add a number of frames to a timecode.

[src]

Performs the += operation.

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

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

The resulting type after applying the - operator.

[src]

Performs the - operation.

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

Remove a number of frames from a timecode.

[src]

Performs the -= operation.

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

Create a timecode with the the given frame number.

[src]

Performs the conversion.

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

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

The resulting type after applying the + operator.

[src]

Performs the + operation.

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

Add a number of frames to a timecode.

[src]

Performs the += operation.

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

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

The resulting type after applying the - operator.

[src]

Performs the - operation.

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

Remove a number of frames from a timecode.

[src]

Performs the -= operation.

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

Create a timecode with the the given frame number.

[src]

Performs the conversion.

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

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

The resulting type after applying the + operator.

[src]

Performs the + operation.

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

Add a number of frames to a timecode.

[src]

Performs the += operation.

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

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

The resulting type after applying the - operator.

[src]

Performs the - operation.

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

Remove a number of frames from a timecode.

[src]

Performs the -= operation.

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

Create a timecode with the the given frame number.

[src]

Performs the conversion.

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

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

The resulting type after applying the + operator.

[src]

Performs the + operation.

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

Add a number of frames to a timecode.

[src]

Performs the += operation.

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

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

The resulting type after applying the - operator.

[src]

Performs the - operation.

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

Remove a number of frames from a timecode.

[src]

Performs the -= operation.

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

Create a timecode with the the given frame number.

[src]

Performs the conversion.

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

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

The resulting type after applying the + operator.

[src]

Performs the + operation.

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

Add a number of frames to a timecode.

[src]

Performs the += operation.

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

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

The resulting type after applying the - operator.

[src]

Performs the - operation.

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

Remove a number of frames from a timecode.

[src]

Performs the -= operation.

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

Create a timecode with the the given frame number.

[src]

Performs the conversion.

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

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

The resulting type after applying the + operator.

[src]

Performs the + operation.

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

Add a number of frames to a timecode.

[src]

Performs the += operation.

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

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

The resulting type after applying the - operator.

[src]

Performs the - operation.

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

Remove a number of frames from a timecode.

[src]

Performs the -= operation.

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

Create a timecode with the the given frame number.

[src]

Performs the conversion.

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

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

The resulting type after applying the + operator.

[src]

Performs the + operation.

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

Add a number of frames to a timecode.

[src]

Performs the += operation.

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

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

The resulting type after applying the - operator.

[src]

Performs the - operation.

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

Remove a number of frames from a timecode.

[src]

Performs the -= operation.

impl<T> Add for Timecode<T> where
    T: FrameRate
[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 code doesn't compile so be extra careful!
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());

The resulting type after applying the + operator.

[src]

Performs the + operation.

impl<T> AddAssign for Timecode<T> where
    T: FrameRate
[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());

[src]

Performs the += operation.