pub struct Subtitle {
pub entries: Vec<SubtitleEntry>,
pub metadata: SubtitleMetadata,
pub format: SubtitleFormatType,
}Expand description
Unified subtitle data structure containing entries, metadata, and format information.
This structure represents a complete subtitle file in memory, providing a format-agnostic representation that can be converted between different subtitle formats while preserving as much information as possible.
§Examples
use subx_cli::core::formats::{Subtitle, SubtitleEntry, SubtitleMetadata, SubtitleFormatType};
use std::time::Duration;
let subtitle = Subtitle {
entries: vec![
SubtitleEntry {
index: 1,
start_time: Duration::from_secs(10),
end_time: Duration::from_secs(13),
text: "Hello, world!".to_string(),
styling: None,
}
],
metadata: SubtitleMetadata {
title: Some("Movie Title".to_string()),
language: Some("en".to_string()),
encoding: "UTF-8".to_string(),
frame_rate: Some(23.976),
original_format: SubtitleFormatType::Srt,
},
format: SubtitleFormatType::Srt,
};
println!("Subtitle has {} entries", subtitle.entries.len());Fields§
§entries: Vec<SubtitleEntry>Collection of subtitle entries with timing and text content.
metadata: SubtitleMetadataMetadata information about the subtitle file.
format: SubtitleFormatTypeCurrent format type of the subtitle data.
Implementations§
Source§impl Subtitle
impl Subtitle
Sourcepub fn new(format: SubtitleFormatType, metadata: SubtitleMetadata) -> Self
pub fn new(format: SubtitleFormatType, metadata: SubtitleMetadata) -> Self
Create a new subtitle with the given format and metadata.
§Arguments
format- The subtitle format typemetadata- Metadata associated with the subtitle
§Examples
use subx_cli::core::formats::{Subtitle, SubtitleMetadata, SubtitleFormatType};
let metadata = SubtitleMetadata::default();
let subtitle = Subtitle::new(SubtitleFormatType::Srt, metadata);
assert_eq!(subtitle.entries.len(), 0);Sourcepub fn total_duration(&self) -> Duration
pub fn total_duration(&self) -> Duration
Sourcepub fn has_overlaps(&self) -> bool
pub fn has_overlaps(&self) -> bool
Check if subtitle entries have any timing overlaps.
Returns true if any entry’s start time is before the previous
entry’s end time, indicating overlapping subtitles.
Sourcepub fn sort_entries(&mut self)
pub fn sort_entries(&mut self)
Sort entries by start time to ensure chronological order.
This method is useful after manual manipulation of entries or when merging subtitles from multiple sources.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Subtitle
impl RefUnwindSafe for Subtitle
impl Send for Subtitle
impl Sync for Subtitle
impl Unpin for Subtitle
impl UnwindSafe for Subtitle
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.