webvtt_parser

Struct Vtt

Source
pub struct Vtt<'a> {
    pub slugs: HashMap<&'a str, &'a str>,
    pub style: Option<&'a str>,
    pub cues: Vec<VttCue<'a>>,
}
Expand description

(web)VTT — Web Video Text Tracks This struct represents a parsed VTT file. It contains a list of cues and optional metadata.

Fields§

§slugs: HashMap<&'a str, &'a str>

Top level key-value metadata pairs that might be populated at the very top of the subtitles file. For example:

WEBVTT
Kind: captions
Language: en
§style: Option<&'a str>

Optional global css style can be populated at the very top of the file. If it is present it might be applied globally to all cues.

For example:

STYLE
::cue {
   background-image: linear-gradient(to bottom, dimgray, lightgray);
   color: papayawhip;
   font-size: 50px;
   text-align: center;
   font-family: monospace;
 }
§cues: Vec<VttCue<'a>>

A list of cues that are present in the file. Each cue contains a start and end time, text and optional cue settings.

For example:

WEBVTT
00:00.000 --> 00:05.000
Hey subtitle one

Implementations§

Source§

impl<'a> Vtt<'a>

Source

pub fn parse(content: &'a str) -> Result<Self, VttError>

Parse webvtt subtitles from provided string. Make sure that it does not allocate any string data and only references parts of the original string.

§Example
use webvtt_parser::{Vtt, VttCue, VttCueSettings, Align, Time};

let vtt = Vtt::parse("WEBVTT

00:00.000 --> 00:05.000
Hey subtitle one

00:05.000 --> 00:08.000 align:end
Hey subtitle two
").unwrap();

assert_eq!(vtt.cues.len(), 2);
assert_eq!(vtt.cues[0], VttCue { start: Time::from_milliseconds(0), end: Time::from_milliseconds(5000), text: "Hey subtitle one", name: None, note: None, cue_settings: None });
assert_eq!(vtt.cues[1].cue_settings, Some(VttCueSettings { align: Some(Align::End), position: None, vertical: None, size: None, line: None }));
Source

pub fn to_owned(&self) -> OwnedVtt

Clones all the borrowes strings and returns the owned oversion of the vtt data.

Trait Implementations§

Source§

impl<'a> Clone for Vtt<'a>

Source§

fn clone(&self) -> Vtt<'a>

Returns a copy 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<'a> Debug for Vtt<'a>

Source§

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

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

impl Display for Vtt<'_>

Source§

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

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

impl<'a> From<&'a OwnedVtt> for Vtt<'a>

Source§

fn from(value: &'a OwnedVtt) -> Self

Converts to this type from the input type.
Source§

impl<'a> PartialEq for Vtt<'a>

Source§

fn eq(&self, other: &Vtt<'a>) -> 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 ASubtitle for Vtt<'_>

Source§

impl<'a> Eq for Vtt<'a>

Source§

impl<'a> StructuralPartialEq for Vtt<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Vtt<'a>

§

impl<'a> RefUnwindSafe for Vtt<'a>

§

impl<'a> Send for Vtt<'a>

§

impl<'a> Sync for Vtt<'a>

§

impl<'a> Unpin for Vtt<'a>

§

impl<'a> UnwindSafe for Vtt<'a>

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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToString for T
where T: Display + ?Sized,

Source§

default fn to_string(&self) -> String

Converts the given value to a String. 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.