pub struct TimeDelta { /* private fields */ }
Expand description
Represents a duration between two TimePoints
.
Implementations§
Source§impl TimeDelta
impl TimeDelta
Sourcepub fn from_components(hours: i64, mins: i64, secs: i64, ms: i64) -> TimeDelta
pub fn from_components(hours: i64, mins: i64, secs: i64, ms: i64) -> TimeDelta
Create this time type from all time components.
The components can be negative and/or exceed the its natural limits without error.
For example from_components(0, 0, 3, -2000)
is the same as from_components(0, 0, 1, 0)
.
Sourcepub fn from_msecs(ms: i64) -> TimeDelta
pub fn from_msecs(ms: i64) -> TimeDelta
Create the time type from a given number of milliseconds.
Sourcepub fn from_csecs(ms: i64) -> TimeDelta
pub fn from_csecs(ms: i64) -> TimeDelta
Create the time type from a given number of hundreth seconds (10 milliseconds).
Sourcepub fn from_mins(mins: i64) -> TimeDelta
pub fn from_mins(mins: i64) -> TimeDelta
Create the time type with a given number of minutes.
Examples found in repository?
examples/example1.rs (line 28)
16fn main() {
17 // your setup goes here
18 let path = PathBuf::from("path/your_example_file.ssa");
19 let file_content: String = read_file(&path); // your own load routine
20
21 // parse the file
22 let format = get_subtitle_format(path.extension(), file_content.as_bytes()).expect("unknown format");
23 let mut subtitle_file = parse_str(format, &file_content, 25.0).expect("parser error");
24 let mut subtitle_entries: Vec<SubtitleEntry> = subtitle_file.get_subtitle_entries().expect("unexpected error");
25
26 // shift all subtitle entries by 1 minute and append "subparse" to each subtitle line
27 for subtitle_entry in &mut subtitle_entries {
28 subtitle_entry.timespan += TimeDelta::from_mins(1);
29
30 // image based subtitles like .idx (VobSub) don't have text, so
31 // a text is optional
32 if let Some(ref mut line_ref) = subtitle_entry.line {
33 line_ref.push_str("subparse");
34 }
35 }
36
37 // update the entries in the subtitle file
38 subtitle_file.update_subtitle_entries(&subtitle_entries).expect("unexpected error");
39
40 // print the corrected file to stdout
41 let data: Vec<u8> = subtitle_file.to_data().expect("unexpected errror");
42 let data_string = String::from_utf8(data).expect("UTF-8 conversion error");
43 println!("{}", data_string);
44}
Sourcepub fn from_hours(mins: i64) -> TimeDelta
pub fn from_hours(mins: i64) -> TimeDelta
Create the time type with a given number of hours.
Sourcepub fn msecs_comp(&self) -> i64
pub fn msecs_comp(&self) -> i64
Get the milliseconds component in a range of [0, 999].
Sourcepub fn csecs_comp(&self) -> i64
pub fn csecs_comp(&self) -> i64
Get the hundreths seconds component in a range of [0, 99].
Sourcepub fn is_negative(&self) -> bool
pub fn is_negative(&self) -> bool
Return true
if the represented time is negative.
Trait Implementations§
Source§impl AddAssign<TimeDelta> for TimePoint
impl AddAssign<TimeDelta> for TimePoint
Source§fn add_assign(&mut self, r: TimeDelta)
fn add_assign(&mut self, r: TimeDelta)
Performs the
+=
operation. Read moreSource§impl AddAssign<TimeDelta> for TimeSpan
impl AddAssign<TimeDelta> for TimeSpan
Source§fn add_assign(&mut self, r: TimeDelta)
fn add_assign(&mut self, r: TimeDelta)
Performs the
+=
operation. Read moreSource§impl AddAssign for TimeDelta
impl AddAssign for TimeDelta
Source§fn add_assign(&mut self, r: TimeDelta)
fn add_assign(&mut self, r: TimeDelta)
Performs the
+=
operation. Read moreSource§impl Ord for TimeDelta
impl Ord for TimeDelta
Source§impl PartialOrd for TimeDelta
impl PartialOrd for TimeDelta
Source§impl SubAssign<TimeDelta> for TimePoint
impl SubAssign<TimeDelta> for TimePoint
Source§fn sub_assign(&mut self, r: TimeDelta)
fn sub_assign(&mut self, r: TimeDelta)
Performs the
-=
operation. Read moreSource§impl SubAssign<TimeDelta> for TimeSpan
impl SubAssign<TimeDelta> for TimeSpan
Source§fn sub_assign(&mut self, r: TimeDelta)
fn sub_assign(&mut self, r: TimeDelta)
Performs the
-=
operation. Read moreSource§impl SubAssign for TimeDelta
impl SubAssign for TimeDelta
Source§fn sub_assign(&mut self, r: TimeDelta)
fn sub_assign(&mut self, r: TimeDelta)
Performs the
-=
operation. Read moreimpl Copy for TimeDelta
impl Eq for TimeDelta
impl StructuralPartialEq for TimeDelta
Auto Trait Implementations§
impl Freeze for TimeDelta
impl RefUnwindSafe for TimeDelta
impl Send for TimeDelta
impl Sync for TimeDelta
impl Unpin for TimeDelta
impl UnwindSafe for TimeDelta
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more