Skip to content

Commit 072b76f

Browse files
committed
Replace SubtitleFile with SubtitleFileInterface
1 parent 062057b commit 072b76f

File tree

8 files changed

+25
-25
lines changed

8 files changed

+25
-25
lines changed

examples/example2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
extern crate subparse;
22

33
use subparse::timetypes::{TimePoint, TimeSpan};
4-
use subparse::{SrtFile, SubtitleFile};
4+
use subparse::{SrtFile, SubtitleFileInterface};
55

66
fn main() {
77
// example how to create a fresh .srt file

src/formats/idx.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use self::errors::ErrorKind::*; // the crate wide error type (we use a custom error type here)
66
use self::errors::*;
77
use super::common::*;
8-
use crate::{SubtitleEntry, SubtitleFile};
8+
use crate::{SubtitleEntry, SubtitleFileInterface};
99

1010
use crate::errors::Result as SubtitleParserResult;
1111
use combine::char::*;
@@ -66,7 +66,7 @@ impl IdxFile {
6666
}
6767
}
6868

69-
impl SubtitleFile for IdxFile {
69+
impl SubtitleFileInterface for IdxFile {
7070
fn get_subtitle_entries(&self) -> SubtitleParserResult<Vec<SubtitleEntry>> {
7171
let timings: Vec<_> = self
7272
.v

src/formats/microdvd.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use self::errors::ErrorKind::*;
66
use self::errors::*;
7-
use crate::{SubtitleEntry, SubtitleFile};
7+
use crate::{SubtitleEntry, SubtitleFileInterface};
88

99
use crate::errors::Result as SubtitleParserResult;
1010
use crate::formats::common::*;
@@ -233,7 +233,7 @@ impl MdvdFile {
233233
}
234234
}
235235

236-
impl SubtitleFile for MdvdFile {
236+
impl SubtitleFileInterface for MdvdFile {
237237
fn get_subtitle_entries(&self) -> SubtitleParserResult<Vec<SubtitleEntry>> {
238238
Ok(self.v.iter().map(|line| line.to_subtitle_entry(self.fps)).collect())
239239
}
@@ -339,7 +339,7 @@ impl SubtitleFile for MdvdFile {
339339
#[cfg(test)]
340340
mod tests {
341341
use super::*;
342-
use SubtitleFile;
342+
use SubtitleFileInterface;
343343

344344
/// Parse string with `MdvdFile`, and reencode it with `MdvdFile`.
345345
fn mdvd_reconstruct(s: &str) -> String {

src/formats/mod.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub mod ssa;
1010
pub mod vobsub;
1111

1212
use crate::errors::*;
13-
use crate::SubtitleFile;
13+
use crate::SubtitleFileInterface;
1414
use encoding_rs::Encoding;
1515
use std::ffi::OsStr;
1616

@@ -124,22 +124,22 @@ pub fn get_subtitle_format_err(extension: Option<&OsStr>, content: &[u8]) -> Res
124124
}
125125

126126
/// This trick works around the limitation, that trait objects can not require Sized (or Clone).
127-
pub trait ClonableSubtitleFile: SubtitleFile + Send + Sync {
127+
pub trait ClonableSubtitleFileInterface: SubtitleFileInterface + Send + Sync {
128128
/// Returns a boxed clone
129-
fn clone_box(&self) -> Box<ClonableSubtitleFile>;
129+
fn clone_box(&self) -> Box<ClonableSubtitleFileInterface>;
130130
}
131-
impl<T> ClonableSubtitleFile for T
131+
impl<T> ClonableSubtitleFileInterface for T
132132
where
133-
T: SubtitleFile + Clone + Send + Sync + 'static,
133+
T: SubtitleFileInterface + Clone + Send + Sync + 'static,
134134
{
135-
fn clone_box(&self) -> Box<ClonableSubtitleFile> {
135+
fn clone_box(&self) -> Box<ClonableSubtitleFileInterface> {
136136
Box::new(Clone::clone(self))
137137
}
138138
}
139139

140140
// We can now implement Clone manually by forwarding to clone_box.
141-
impl Clone for Box<ClonableSubtitleFile> {
142-
fn clone(&self) -> Box<ClonableSubtitleFile> {
141+
impl Clone for Box<ClonableSubtitleFileInterface> {
142+
fn clone(&self) -> Box<ClonableSubtitleFileInterface> {
143143
self.clone_box()
144144
}
145145
}
@@ -151,7 +151,7 @@ impl Clone for Box<ClonableSubtitleFile> {
151151
/// # Mandatory format specific options
152152
///
153153
/// See `parse_bytes`.
154-
pub fn parse_str(format: SubtitleFormat, content: &str, fps: f64) -> Result<Box<ClonableSubtitleFile>> {
154+
pub fn parse_str(format: SubtitleFormat, content: &str, fps: f64) -> Result<Box<ClonableSubtitleFileInterface>> {
155155
match format {
156156
SubtitleFormat::SubRip => Ok(Box::new(srt::SrtFile::parse(content)?)),
157157
SubtitleFormat::SubStationAlpha => Ok(Box::new(ssa::SsaFile::parse(content)?)),
@@ -185,7 +185,7 @@ fn decode_bytes_to_string(content: &[u8], encoding: &'static Encoding) -> Result
185185
/// seconds/minutes/... but in frame numbers. So the timing `0 to 30` means "show subtitle for one second"
186186
/// for a 30fps video, and "show subtitle for half second" for 60fps videos. The parameter specifies how
187187
/// frame numbers are converted into timestamps.
188-
pub fn parse_bytes(format: SubtitleFormat, content: &[u8], encoding: &'static Encoding, fps: f64) -> Result<Box<ClonableSubtitleFile>> {
188+
pub fn parse_bytes(format: SubtitleFormat, content: &[u8], encoding: &'static Encoding, fps: f64) -> Result<Box<ClonableSubtitleFileInterface>> {
189189
match format {
190190
SubtitleFormat::SubRip => Ok(Box::new(srt::SrtFile::parse(&decode_bytes_to_string(content, encoding)?)?)),
191191
SubtitleFormat::SubStationAlpha => Ok(Box::new(ssa::SsaFile::parse(&decode_bytes_to_string(content, encoding)?)?)),

src/formats/srt.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use self::errors::ErrorKind::*;
66
use self::errors::*;
7-
use crate::{SubtitleEntry, SubtitleFile};
7+
use crate::{SubtitleEntry, SubtitleFileInterface};
88

99
use crate::errors::Result as SubtitleParserResult;
1010
use crate::formats::common::*;
@@ -171,7 +171,7 @@ impl SrtFile {
171171
}
172172
}
173173

174-
impl SubtitleFile for SrtFile {
174+
impl SubtitleFileInterface for SrtFile {
175175
fn get_subtitle_entries(&self) -> SubtitleParserResult<Vec<SubtitleEntry>> {
176176
let timings = self
177177
.v
@@ -234,7 +234,7 @@ mod tests {
234234
#[test]
235235
fn create_srt_test() {
236236
use crate::timetypes::{TimePoint, TimeSpan};
237-
use crate::SubtitleFile;
237+
use crate::SubtitleFileInterface;
238238

239239
let lines = vec![
240240
(

src/formats/ssa.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// License, v. 2.0. If a copy of the MPL was not distributed with this
33
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
44

5-
use crate::{SubtitleEntry, SubtitleFile};
5+
use crate::{SubtitleEntry, SubtitleFileInterface};
66

77
use crate::errors::Result as SubtitleParserResult;
88
use crate::formats::common::*;
@@ -409,7 +409,7 @@ impl SsaFile {
409409
}
410410
}
411411

412-
impl SubtitleFile for SsaFile {
412+
impl SubtitleFileInterface for SsaFile {
413413
fn get_subtitle_entries(&self) -> SubtitleParserResult<Vec<SubtitleEntry>> {
414414
// it's unfortunate we have to clone the file before using
415415
// `get_subtitle_entries_mut()`, but otherwise we'd have to copy the`

src/formats/vobsub.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use self::errors::*;
66
use crate::errors::Result as SubtitleParserResult;
77
use crate::timetypes::{TimePoint, TimeSpan};
8-
use crate::{SubtitleEntry, SubtitleFile, SubtitleFormat};
8+
use crate::{SubtitleEntry, SubtitleFileInterface, SubtitleFormat};
99
use failure::ResultExt;
1010

1111
use vobsub;
@@ -70,7 +70,7 @@ impl VobFile {
7070
}
7171
}
7272

73-
impl SubtitleFile for VobFile {
73+
impl SubtitleFileInterface for VobFile {
7474
fn get_subtitle_entries(&self) -> SubtitleParserResult<Vec<SubtitleEntry>> {
7575
Ok(self
7676
.lines

src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ pub use formats::{
4545
get_subtitle_format, get_subtitle_format_by_extension, get_subtitle_format_by_extension_err, get_subtitle_format_err,
4646
is_valid_extension_for_subtitle_format, parse_bytes, parse_str,
4747
};
48-
pub use formats::{ClonableSubtitleFile, SubtitleFormat};
48+
pub use formats::{ClonableSubtitleFileInterface, SubtitleFormat};
4949
use timetypes::TimeSpan;
5050

5151
/// This trait represents the generic interface for reading and writing subtitle information across all subtitle formats.
5252
///
5353
/// This trait allows you to read, change and rewrite the subtitle file.
54-
pub trait SubtitleFile {
54+
pub trait SubtitleFileInterface {
5555
/// The subtitle entries can be changed by calling `update_subtitle_entries()`.
5656
fn get_subtitle_entries(&self) -> Result<Vec<SubtitleEntry>>;
5757

0 commit comments

Comments
 (0)