Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/text/wrap
diff options
context:
space:
mode:
authorFrançois Laignel <fengalin@free.fr>2021-10-09 13:17:05 +0300
committerFrançois Laignel <fengalin@free.fr>2021-10-18 16:09:47 +0300
commit27b9f0d868f436e9b2bcc3e51f393c40b56fcc02 (patch)
tree93c0db7b1cf26ea7d0e3a4d70a7d2844c2e00975 /text/wrap
parentbd8a7e8df7e8ebf751b2d00fe6a096d726683c00 (diff)
Improve usability thanks to opt-ops
The crate option-operations simplifies usage when dealing with `Option`s, which is often the case with `ClockTime`.
Diffstat (limited to 'text/wrap')
-rw-r--r--text/wrap/src/gsttextwrap/imp.rs27
1 files changed, 8 insertions, 19 deletions
diff --git a/text/wrap/src/gsttextwrap/imp.rs b/text/wrap/src/gsttextwrap/imp.rs
index d01e310aa..ef6bbeb07 100644
--- a/text/wrap/src/gsttextwrap/imp.rs
+++ b/text/wrap/src/gsttextwrap/imp.rs
@@ -203,10 +203,9 @@ impl TextWrap {
let add_buffer = state
.start_ts
- .zip(Some(accumulate_time))
- .map_or(false, |(start_ts, accumulate_time)| {
- start_ts + accumulate_time < pts
- });
+ .opt_add(accumulate_time)
+ .opt_lt(pts)
+ .unwrap_or(false);
if add_buffer {
let mut buf =
@@ -214,12 +213,8 @@ impl TextWrap {
{
let buf_mut = buf.get_mut().unwrap();
buf_mut.set_pts(state.start_ts);
- buf_mut.set_duration(
- state
- .end_ts
- .zip(state.start_ts)
- .and_then(|(end_ts, start_ts)| end_ts.checked_sub(start_ts)),
- );
+ buf_mut
+ .set_duration(state.end_ts.opt_checked_sub(state.start_ts).ok().flatten());
}
bufferlist.get_mut().unwrap().add(buf);
@@ -262,10 +257,7 @@ impl TextWrap {
.collect::<Vec<String>>()
.join("\n");
} else {
- let duration = state
- .end_ts
- .zip(state.start_ts)
- .and_then(|(end_ts, start_ts)| end_ts.checked_sub(start_ts));
+ let duration = state.end_ts.opt_checked_sub(state.start_ts).ok().flatten();
let contents = chunk
.iter()
.map(|l| l.to_string())
@@ -291,7 +283,7 @@ impl TextWrap {
}
current_text = trailing;
- state.end_ts = state.end_ts.map(|end_ts| end_ts + duration_per_word);
+ state.end_ts = state.end_ts.opt_add(duration_per_word);
}
state.current_text = current_text;
@@ -399,10 +391,7 @@ impl TextWrap {
let buf_mut = buf.get_mut().unwrap();
buf_mut.set_pts(state.start_ts);
buf_mut.set_duration(
- state
- .end_ts
- .zip(state.start_ts)
- .and_then(|(end_ts, start_ts)| end_ts.checked_sub(start_ts)),
+ state.end_ts.opt_checked_sub(state.start_ts).ok().flatten(),
);
}