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>
impl<'a> Vtt<'a>
Sourcepub fn parse(content: &'a str) -> Result<Self, VttError>
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 }));
Trait Implementations§
impl ASubtitle for Vtt<'_>
impl<'a> Eq for Vtt<'a>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)