Struct substudy::time::Period
[−]
[src]
pub struct Period { // some fields omitted }
A period of time, in seconds. The beginning is guaranteed to be less
than the end, and all times are positive. This is lightweight
structure which implements Copy
, so it can be passed by value.
use substudy::time::Period; let period = Period::new(1.0, 5.0).unwrap(); assert_eq!(1.0, period.begin()); assert_eq!(5.0, period.end()); assert_eq!(4.0, period.duration()); assert_eq!(3.0, period.midpoint());
Methods
impl Period
[src]
fn new(begin: f32, end: f32) -> Result<Period>
Create a new time period.
fn from_union_opt(p1: Option<Period>, p2: Option<Period>) -> Option<Period>
Construct a time period from two optional time periods, taking the union if both are present. This is normally used when working with aligned subtitle pairs, either of which might be missing.
use substudy::time::Period; assert_eq!(None, Period::from_union_opt(None, None)); let p1 = Period::new(1.0, 2.0).unwrap(); let p2 = Period::new(2.5, 3.0).unwrap(); assert_eq!(Some(p1), Period::from_union_opt(Some(p1), None)); assert_eq!(Some(Period::new(1.0, 3.0).unwrap()), Period::from_union_opt(Some(p1), Some(p2)));
fn begin(&self) -> f32
The beginning of this time period.
fn end(&self) -> f32
The end of this time period.
fn duration(&self) -> f32
How long this time period lasts.
fn midpoint(&self) -> f32
The midpoint of this time period.
fn grow(&self, before: f32, after: f32) -> Period
Grow this time period by the specified amount, making any necessary adjustments to keep it valid.
use substudy::time::Period; let period = Period::new(1.0, 5.0).unwrap(); assert_eq!(Period::new(0.0, 7.0).unwrap(), period.grow(1.5, 2.0));
fn union(&self, other: Period) -> Period
Calculate the smallest time period containing this time period and another.
use substudy::time::Period; let p1 = Period::new(1.0, 2.0).unwrap(); let p2 = Period::new(2.5, 3.0).unwrap(); assert_eq!(Period::new(1.0, 3.0).unwrap(), p1.union(p2));
fn begin_after(&mut self, limit: f32) -> Result<()>
Make sure this subtitle begins after limit
.
fn end_before(&mut self, limit: f32) -> Result<()>
Truncate this subtitle before limit
, which must be at least
2*MIN_SPACING
greater than the begin time.
fn distance(&self, other: Period) -> Option<f32>
Return the absolute value of the distance between two durations, or
None
if the durations overlap.
use substudy::time::Period; let p1 = Period::new(1.0, 2.0).unwrap(); let p2 = Period::new(2.0, 3.0).unwrap(); let p3 = Period::new(2.5, 3.0).unwrap(); assert_eq!(Some(0.5), p1.distance(p3)); assert_eq!(Some(0.5), p3.distance(p1)); assert_eq!(Some(0.0), p1.distance(p2)); assert_eq!(None, p2.distance(p3));
fn overlap(&self, other: Period) -> f32
Return the total amount of time which appears in both durations.
use substudy::time::Period; let p1 = Period::new(1.0, 2.0).unwrap(); let p2 = Period::new(2.0, 3.0).unwrap(); let p3 = Period::new(2.5, 3.0).unwrap(); assert_eq!(0.0, p1.overlap(p3)); assert_eq!(0.0, p3.overlap(p1)); assert_eq!(0.0, p1.overlap(p2)); assert_eq!(0.5, p2.overlap(p3));
Trait Implementations
impl PartialEq for Period
[src]
fn eq(&self, __arg_0: &Period) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Period) -> bool
This method tests for !=
.
impl Debug for Period
[src]
impl Copy for Period
[src]
impl Clone for Period
[src]
fn clone(&self) -> Period
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl Encodable for Period
[src]
impl ToTimestamp for Period
[src]
fn to_timestamp(&self) -> String
Convert to a string describing this time.
fn to_file_timestamp(&self) -> String
Convert to a string describing this time, replacing periods with "_". Read more