pub struct SubtitleEntry {
pub index: usize,
pub start_time: Duration,
pub end_time: Duration,
pub text: String,
pub styling: Option<StylingInfo>,
}Expand description
Single subtitle entry containing timing, index, and text information.
This structure represents an individual subtitle entry with its timing, content, and optional styling information. It provides the basic building block for all subtitle formats.
§Timing Constraints
start_timemust be less thanend_time- Times are represented as
Durationfrom the beginning of the media - Minimum recommended duration is 1 second for readability
- Maximum recommended duration is 7 seconds for standard subtitles
§Text Content
- Supports Unicode text for international character sets
- May contain format-specific markup (HTML tags for SRT, ASS tags for ASS format)
- Line breaks are preserved and format-dependent (\n, \N, or
)
§Examples
use subx_cli::core::formats::{SubtitleEntry, StylingInfo};
use std::time::Duration;
// Basic subtitle entry
let entry = SubtitleEntry {
index: 1,
start_time: Duration::from_millis(10500), // 10.5 seconds
end_time: Duration::from_millis(13750), // 13.75 seconds
text: "Hello, world!".to_string(),
styling: None,
};
// Entry with styling
let styled_entry = SubtitleEntry {
index: 2,
start_time: Duration::from_secs(15),
end_time: Duration::from_secs(18),
text: "<b>Bold text</b>".to_string(),
styling: Some(StylingInfo {
bold: true,
..Default::default()
}),
};
assert_eq!(entry.duration(), Duration::from_millis(3250));
assert!(entry.is_valid_timing());Fields§
§index: usizeSequential number of the subtitle entry (1-based indexing).
This index is used for ordering and reference purposes. Most formats expect continuous numbering starting from 1.
start_time: DurationStart timestamp of the subtitle entry.
Represents when the subtitle should first appear on screen, measured from the beginning of the media file.
end_time: DurationEnd timestamp of the subtitle entry.
Represents when the subtitle should disappear from screen.
Must be greater than start_time.
text: StringText content of the subtitle entry.
May contain format-specific markup for styling and line breaks. Unicode content is fully supported for international subtitles.
styling: Option<StylingInfo>Optional styling information for the subtitle entry.
Contains font, color, and formatting information. Not all formats support styling, and some styling may be lost during conversion.
Implementations§
Source§impl SubtitleEntry
impl SubtitleEntry
Sourcepub fn new(
index: usize,
start_time: Duration,
end_time: Duration,
text: String,
) -> Self
pub fn new( index: usize, start_time: Duration, end_time: Duration, text: String, ) -> Self
Create a new subtitle entry with basic timing and text.
§Arguments
index- Sequential number of the entry (1-based)start_time- When the subtitle should appearend_time- When the subtitle should disappeartext- The subtitle text content
§Panics
Panics if start_time >= end_time.
§Examples
use subx_cli::core::formats::SubtitleEntry;
use std::time::Duration;
let entry = SubtitleEntry::new(
1,
Duration::from_secs(10),
Duration::from_secs(13),
"Hello!".to_string()
);Sourcepub fn is_valid_timing(&self) -> bool
pub fn is_valid_timing(&self) -> bool
Check if the timing of this entry is valid.
Returns true if start_time < end_time and both are valid durations.
Sourcepub fn overlaps_with(&self, other: &SubtitleEntry) -> bool
pub fn overlaps_with(&self, other: &SubtitleEntry) -> bool
Sourcepub fn plain_text(&self) -> String
pub fn plain_text(&self) -> String
Get the text content without any format-specific markup.
Removes common formatting tags like HTML tags for SRT format. This is useful for text analysis and search operations.
Trait Implementations§
Source§impl Clone for SubtitleEntry
impl Clone for SubtitleEntry
Source§fn clone(&self) -> SubtitleEntry
fn clone(&self) -> SubtitleEntry
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more