[][src]Struct srtlib::Subtitles

pub struct Subtitles(_);

A collection of Subtitle structs.

Provides an easy way to represent an entire .srt subtitle file.

Examples

use srtlib::{Subtitle, Subtitles};

let mut subs = Subtitles::new();
subs.push(Subtitle::parse("1\n00:00:00,000 --> 00:00:01,000\nHello world!".to_string()).unwrap());
subs.push(Subtitle::parse("2\n00:00:01,200 --> 00:00:03,100\nThis is a subtitle!".to_string()).unwrap());

assert_eq!(subs.to_string(),
           "1\n00:00:00,000 --> 00:00:01,000\nHello world!\n\n2\n00:00:01,200 --> 00:00:03,100\nThis is a subtitle!");

Implementations

impl Subtitles[src]

pub fn new() -> Subtitles[src]

Constructs a new(empty) Subtitles collection.

pub fn new_from_vec(v: Vec<Subtitle>) -> Subtitles[src]

Constructs a new Subtitles collection from a vector of Subtitle structs.

pub fn parse_from_str(input: String) -> Result<Subtitles, ParsingError>[src]

Constructs a new Subtitles collection by parsing a string with the format "subtitle\n\nsubtitle\n\n..." where subtitle is a string formatted as described in the Subtitle struct documentation.

Errors

If this function encounters anything unexpected while parsing the string, a corresponding error variant will be returned.

pub fn parse_from_file(
    path: &str,
    encoding: Option<&str>
) -> Result<Subtitles, ParsingError>
[src]

Constructs a new Subtitles collection by parsing a .srt file.

encoding should either be Some("encoding-name") or None if using utf-8. For example if the file is using the ISO-8859-7 encoding (informally referred to as Latin/Greek) we could use:

use srtlib::Subtitles;
let subs = Subtitles::parse_from_file("subtitles.srt", Some("iso-8859-7"))?;

or the equivalent:

let subs = Subtitles::parse_from_file("subtitles.srt", Some("greek"))?;

For a list of encoding names (labels) refer to the Encoding Standard.

Errors

If the encoding label provided is not one of the labels specified by the Encoding Standard, a BadEncodingName error variant will be returned.

If something unexpected is encountered during the parsing of the contents of the file, a corresponding error variant will be returned.

pub fn write_to_file(
    &self,
    path: &str,
    encoding: Option<&str>
) -> Result<(), ParsingError>
[src]

Writes the contents of this Subtitles collection to a .srt file with the correct formatting.

encoding should either be Some("encoding-name") or None if using utf-8. For example if the file is using the ISO-8859-7 encoding (informally referred to as Latin/Greek) we could use:

use srtlib::Subtitles;

let subs = Subtitles::new();
// Work with the subtitles...
subs.write_to_file("output.srt", Some("iso-8859-7")).unwrap();

or the equivalent:

subs.write_to_file("output.srt", Some("greek")).unwrap();

For a list of encoding names (labels) refer to the Encoding Standard.

Errors

If something goes wrong during the creation of the file using the specified path, an IOError error variant will be returned.

If the encoding label provided is not one of the labels specified by the Encoding Standard, a BadEncodingName error variant will be returned.

pub fn to_vec(self) -> Vec<Subtitle>[src]

Returns the Subtitles collection as a simple vector of Subtitle structs.

pub fn len(&self) -> usize[src]

Returns the number of Subtitles in the collection.

pub fn push(&mut self, sub: Subtitle)[src]

Adds a new subtitle at the end of the subtitles.

Trait Implementations

impl Debug for Subtitles[src]

impl Display for Subtitles[src]

impl<I: SliceIndex<[Subtitle]>> Index<I> for Subtitles[src]

type Output = I::Output

The returned type after indexing.

impl IntoIterator for Subtitles[src]

type Item = Subtitle

The type of the elements being iterated over.

type IntoIter = IntoIter<Self::Item>

Which kind of iterator are we turning this into?

impl<'l> IntoIterator for &'l Subtitles[src]

type Item = &'l Subtitle

The type of the elements being iterated over.

type IntoIter = Iter<'l, Subtitle>

Which kind of iterator are we turning this into?

impl<'l> IntoIterator for &'l mut Subtitles[src]

type Item = &'l mut Subtitle

The type of the elements being iterated over.

type IntoIter = IterMut<'l, Subtitle>

Which kind of iterator are we turning this into?

impl PartialEq<Subtitles> for Subtitles[src]

impl StructuralPartialEq for Subtitles[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.