[][src]Struct srtlib::Subtitle

pub struct Subtitle {
    pub num: usize,
    pub start_time: Timestamp,
    pub end_time: Timestamp,
    pub text: String,
}

A single subtitle.

Contains the numeric counter, the beginning and end timestamps and the text of the subtitle.

Examples

use srtlib::Subtitle;
use srtlib::Timestamp;

let sub = Subtitle::new(1, Timestamp::new(0, 0, 0, 0), Timestamp::new(0, 0, 1, 0), "Hello world".to_string());
assert_eq!(sub.to_string(), "1\n00:00:00,000 --> 00:00:01,000\nHello world");

let sub = Subtitle::parse("2\n00:00:01,500 --> 00:00:02,500\nFooBar".to_string()).unwrap();
assert_eq!(sub.text, "FooBar");

Fields

num: usizestart_time: Timestampend_time: Timestamptext: String

Implementations

impl Subtitle[src]

pub fn new(
    num: usize,
    start_time: Timestamp,
    end_time: Timestamp,
    text: String
) -> Subtitle
[src]

Constructs a new Subtitle.

pub fn parse(input: String) -> Result<Subtitle, ParsingError>[src]

Construct a new subtitle by parsing a string with the format "num\nstart --> end\ntext" where start and end are timestamps using the format hours:minutes:seconds,milliseconds.

Errors

If this function encounters anything unexpected while parsing the string, a corresponding error variant will be returned.

pub fn add_hours(&mut self, n: i32)[src]

Moves the start and end timestamps n hours forward in time. Negative values may be provided in order to move the timestamps back in time.

Panics

Panics if we exceed the upper limit or go below zero.

pub fn add_minutes(&mut self, n: i32)[src]

Moves the start and end timestamps n minutes forward in time. Negative values may be provided in order to move the timestamps back in time.

Panics

Panics if we exceed the upper limit or go below zero.

pub fn add_seconds(&mut self, n: i32)[src]

Moves the start and end timestamps n seconds forward in time. Negative values may be provided in order to move the timestamps back in time.

Panics

Panics if we exceed the upper limit or go below zero.

pub fn add_milliseconds(&mut self, n: i32)[src]

Moves the start and end timestamps n milliseconds forward in time. Negative values may be provided in order to move the timestamps back in time.

Panics

Panics if we exceed the upper limit or go below zero.

Trait Implementations

impl Debug for Subtitle[src]

impl Display for Subtitle[src]

impl Eq for Subtitle[src]

impl Hash for Subtitle[src]

impl Ord for Subtitle[src]

impl PartialEq<Subtitle> for Subtitle[src]

impl PartialOrd<Subtitle> for Subtitle[src]

impl StructuralEq for Subtitle[src]

impl StructuralPartialEq for Subtitle[src]

Auto Trait Implementations

Blanket Implementations

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

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

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

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

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

impl<T> ToString for T where
    T: Display + ?Sized
[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.