SubtitleEntry

Struct SubtitleEntry 

Source
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_time must be less than end_time
  • Times are represented as Duration from 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: usize

Sequential 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: Duration

Start timestamp of the subtitle entry.

Represents when the subtitle should first appear on screen, measured from the beginning of the media file.

§end_time: Duration

End timestamp of the subtitle entry.

Represents when the subtitle should disappear from screen. Must be greater than start_time.

§text: String

Text 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

Source

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 appear
  • end_time - When the subtitle should disappear
  • text - 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()
);
Source

pub fn duration(&self) -> Duration

Calculate the duration of this subtitle entry.

Returns the time span from start to end of the subtitle.

§Examples
assert_eq!(entry.duration(), Duration::from_secs(3));
Source

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.

Source

pub fn overlaps_with(&self, other: &SubtitleEntry) -> bool

Check if this entry overlaps with another entry.

§Arguments
  • other - Another subtitle entry to check against
§Returns

Returns true if the time ranges overlap.

Source

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

Source§

fn clone(&self) -> SubtitleEntry

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SubtitleEntry

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,