Skip to main content

SubtitleTrack

Struct SubtitleTrack 

Source
pub struct SubtitleTrack {
    pub events: Vec<SubtitleEvent>,
    pub language: Option<String>,
}
Expand description

A parsed subtitle track containing ordered events.

Fields§

§events: Vec<SubtitleEvent>

Ordered list of subtitle events.

§language: Option<String>

BCP-47 language tag when available (e.g. "en", "ja").

Implementations§

Source§

impl SubtitleTrack

Source

pub fn from_srt(input: &str) -> Result<Self, SubtitleError>

Parse a SubRip (.srt) subtitle string.

Supports multi-line cues and HTML-style tags (<i>, <b>, <u>). Malformed blocks are skipped with log::warn!.

§Errors

Returns SubtitleError::NoEvents when no valid events are found.

Source

pub fn from_ass(input: &str) -> Result<Self, SubtitleError>

Parse an ASS/SSA subtitle string.

Reads the [Events] section only. Override tags ({...}) are preserved in SubtitleEvent::raw and stripped for SubtitleEvent::text. Malformed Dialogue: lines are skipped.

§Errors

Returns SubtitleError::NoEvents when no valid events are found.

Source

pub fn from_vtt(input: &str) -> Result<Self, SubtitleError>

Parse a WebVTT (.vtt) subtitle string.

Cue identifiers are optional. Voice span tags (<v Speaker>) and other HTML tags are stripped for SubtitleEvent::text. Malformed cues are skipped with log::warn!.

§Errors

Returns SubtitleError::ParseError when the WEBVTT header is missing, or SubtitleError::NoEvents when no valid cues are found.

Source

pub fn to_srt(&self) -> String

Serialize this track to a SubRip (.srt) string.

Events are numbered sequentially starting at 1. The raw field is written as the cue body so that style tags round-trip intact. Events with empty text produce a blank-line body so that the sequential index is preserved.

Timestamp format: HH:MM:SS,mmm --> HH:MM:SS,mmm.

Source

pub fn to_ass(&self) -> String

Serialize this track to an ASS/SSA string.

Writes a minimal but valid file containing [Script Info], [V4+ Styles] (one default style), and [Events]. The raw field is written as the Text column so that override tags round-trip intact. Style and Name metadata fields are restored from SubtitleEvent::metadata when present.

Timestamp format: H:MM:SS.cc (centiseconds).

Source

pub fn to_vtt(&self) -> String

Serialize this track to a WebVTT (.vtt) string.

Writes the mandatory WEBVTT header followed by one cue per event. The raw field is written as the cue body so that voice span tags round-trip intact.

Timestamp format: HH:MM:SS.mmm --> HH:MM:SS.mmm.

Source

pub fn write_to_file(&self, path: impl AsRef<Path>) -> Result<(), SubtitleError>

Write this track to path, choosing the serializer by file extension.

Supported extensions: .srt, .ass, .ssa, .vtt.

§Errors

Returns SubtitleError::UnsupportedFormat for unrecognized extensions, or SubtitleError::Io when the file cannot be written.

Source

pub fn from_file(path: impl AsRef<Path>) -> Result<Self, SubtitleError>

Load and parse a subtitle file, auto-detecting the format by extension.

Supported extensions: .srt, .ass, .ssa, .vtt.

§Errors

Returns SubtitleError::UnsupportedFormat for unrecognized extensions, SubtitleError::Io on read failure, or a format-specific error when parsing fails.

Trait Implementations§

Source§

impl Clone for SubtitleTrack

Source§

fn clone(&self) -> SubtitleTrack

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 SubtitleTrack

Source§

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

Formats the value using the given formatter. Read more
Source§

impl PartialEq for SubtitleTrack

Source§

fn eq(&self, other: &SubtitleTrack) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for SubtitleTrack

Source§

impl StructuralPartialEq for SubtitleTrack

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, 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<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.