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
sourceimpl 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
sourceimpl Ord for Subtitle
impl Ord for Subtitle
sourceimpl PartialOrd<Subtitle> for Subtitle
impl PartialOrd<Subtitle> for Subtitle
sourcefn partial_cmp(&self, other: &Subtitle) -> Option<Ordering>
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 · sourcefn lt(&self, other: &Rhs) -> bool
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 · sourcefn le(&self, other: &Rhs) -> bool
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
impl Eq for Subtitle
impl StructuralEq for Subtitle
impl StructuralPartialEq for Subtitle
Auto Trait Implementations
impl RefUnwindSafe for Subtitle
impl Send for Subtitle
impl Sync for Subtitle
impl Unpin for Subtitle
impl UnwindSafe for Subtitle
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more