Struct srtlib::Subtitle

source ·
pub struct Subtitle {
    pub num: usize,
    pub start_time: Timestamp,
    pub end_time: Timestamp,
    pub text: String,
}
Expand description

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: usize§start_time: Timestamp§end_time: Timestamp§text: String

Implementations§

source§

impl Subtitle

source

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

Constructs a new Subtitle.

source

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

Construct a new subtitle by parsing a string with the format “num\nstart –> end\ntext” or the format “num\nstart –> end position_information\ntext” where start and end are timestamps using the format hours:minutes:seconds,milliseconds ; and position_information is position information of any format

§Errors

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

source

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

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.

source

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

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.

source

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

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.

source

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

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.

source

pub fn add(&mut self, timestamp: &Timestamp)

Moves the start and end timestamps forward in time by an amount specified as timestamp.

§Panics

Panics if we exceed the upper limit

source

pub fn sub(&mut self, timestamp: &Timestamp)

Moves the start and end timestamps backward in time by an amount specified as timestamp.

§Panics

Panics if we go below zero

Trait Implementations§

source§

impl Clone for Subtitle

source§

fn clone(&self) -> Subtitle

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Subtitle

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for Subtitle

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Hash for Subtitle

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Ord for Subtitle

source§

fn cmp(&self, other: &Subtitle) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for Subtitle

source§

fn eq(&self, other: &Subtitle) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Subtitle

source§

fn partial_cmp(&self, other: &Subtitle) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Eq for Subtitle

source§

impl StructuralPartialEq for Subtitle

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.