Subtitle

Struct Subtitle 

Source
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: SubtitleMetadata

Metadata information about the subtitle file.

§format: SubtitleFormatType

Current format type of the subtitle data.

Implementations§

Source§

impl Subtitle

Source

pub fn new(format: SubtitleFormatType, metadata: SubtitleMetadata) -> Self

Create a new subtitle with the given format and metadata.

§Arguments
  • format - The subtitle format type
  • metadata - 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);
Source

pub fn total_duration(&self) -> Duration

Get the total duration of the subtitle file.

Returns the time span from the first entry’s start time to the last entry’s end time, or zero if there are no entries.

§Examples
let duration = subtitle.total_duration();
println!("Subtitle duration: {:.2} seconds", duration.as_secs_f32());
Source

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.

Source

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§

Source§

impl Clone for Subtitle

Source§

fn clone(&self) -> Subtitle

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 Subtitle

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,