From 2a4f9fbd5400e189da0047e6e63229e440990d03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Sun, 27 Feb 2022 11:00:30 +0200 Subject: textwrap: Update for textwrap 0.15 API changes --- text/wrap/Cargo.toml | 2 +- text/wrap/src/gsttextwrap/imp.rs | 48 ++++++++-------------------------------- 2 files changed, 10 insertions(+), 40 deletions(-) (limited to 'text') diff --git a/text/wrap/Cargo.toml b/text/wrap/Cargo.toml index 5c5271571..8e33d9410 100644 --- a/text/wrap/Cargo.toml +++ b/text/wrap/Cargo.toml @@ -10,7 +10,7 @@ repository = "https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs" [dependencies] once_cell = "1.0" -textwrap = { version = "0.14", features = ["hyphenation"] } +textwrap = { version = "0.15", features = ["hyphenation"] } hyphenation = "0.8" [dependencies.gst] diff --git a/text/wrap/src/gsttextwrap/imp.rs b/text/wrap/src/gsttextwrap/imp.rs index 7572f3ad9..7db233288 100644 --- a/text/wrap/src/gsttextwrap/imp.rs +++ b/text/wrap/src/gsttextwrap/imp.rs @@ -52,36 +52,8 @@ impl Default for Settings { } } -// FIXME: https://github.com/mgeisler/textwrap/issues/412 -#[derive(Debug)] -struct WrappedWordSplitter(Box); - -impl textwrap::word_splitters::WordSplitter for WrappedWordSplitter { - fn split_points(&self, word: &str) -> Vec { - self.0.split_points(word) - } -} - -impl Clone for WrappedWordSplitter { - fn clone(&self) -> Self { - WrappedWordSplitter(unsafe { - std::mem::transmute::< - Box, - Box, - >(self.0.clone_box()) - }) - } -} - struct State { - options: Option< - textwrap::Options< - 'static, - textwrap::wrap_algorithms::OptimalFit, - textwrap::word_separators::UnicodeBreakProperties, - WrappedWordSplitter, - >, - >, + options: Option>, current_text: String, start_ts: Option, @@ -120,7 +92,9 @@ impl TextWrap { return; } - state.options = if let Some(dictionary) = &settings.dictionary { + let mut options = textwrap::Options::new(settings.columns as usize); + + if let Some(dictionary) = &settings.dictionary { let dict_file = match File::open(dictionary) { Err(err) => { gst::error!(CAT, obj: element, "Failed to open dictionary file: {}", err); @@ -143,16 +117,12 @@ impl TextWrap { Ok(standard) => standard, }; - Some(textwrap::Options::with_word_splitter( - settings.columns as usize, - WrappedWordSplitter(Box::new(standard)), - )) + options.word_splitter = textwrap::WordSplitter::Hyphenation(standard); } else { - Some(textwrap::Options::with_word_splitter( - settings.columns as usize, - WrappedWordSplitter(Box::new(textwrap::word_splitters::NoHyphenation)), - )) - }; + options.word_splitter = textwrap::WordSplitter::NoHyphenation; + } + + state.options = Some(options); } fn sink_chain( -- cgit v1.2.3