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
impl Subtitle
sourcepub fn new(
num: usize,
start_time: Timestamp,
end_time: Timestamp,
text: String
) -> Subtitle
pub fn new( num: usize, start_time: Timestamp, end_time: Timestamp, text: String ) -> Subtitle
Constructs a new Subtitle.
sourcepub fn parse(input: String) -> Result<Subtitle, ParsingError>
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.
sourcepub fn add_hours(&mut self, n: i32)
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.
sourcepub fn add_minutes(&mut self, n: i32)
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.
sourcepub fn add_seconds(&mut self, n: i32)
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.
sourcepub fn add_milliseconds(&mut self, n: i32)
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.
Trait Implementations§
source§impl Ord for Subtitle
impl Ord for Subtitle
source§impl PartialEq for Subtitle
impl PartialEq for Subtitle
source§impl PartialOrd for Subtitle
impl PartialOrd for Subtitle
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more