Skip to main content

Parser

Struct Parser 

Source
pub struct Parser<T: BufRead> { /* private fields */ }
Expand description

A parser to parse M3U/M3U8 file.

Example:

use mediastream_rs::Parser;
use std::io::Cursor;

let mut parser = Parser::new(Cursor::new(r#"
#EXTM3U x-tvg-url="test"
#EXTINF:1 tvg-id="a" provider-type="iptv",A
http://example.com/A.m3u8"#));
parser.parse().unwrap();
let _result = parser.get_playlist();

Implementations§

Source§

impl<T: BufRead> Parser<T>

Source

pub fn new(reader: T) -> Self

Create a parser from a stream (BufRead + Seek + 'static)

Example:

use mediastream_rs::Parser;
use std::io::Cursor;

let mut parser = Parser::new(Cursor::new(r#"
#EXTM3U x-tvg-url="test"
#EXTINF:1 tvg-id="a" provider-type="iptv",A
http://example.com/A.m3u8"#));
Source

pub fn parse(&mut self) -> Result<(), ParseError>

Parse the content from the stream until EOF, and return the error if occurred

Example:

use mediastream_rs::Parser;
use std::io::Cursor;

let mut parser = Parser::new(Cursor::new(r#"
#EXTM3U x-tvg-url="test"
#EXTINF:1 tvg-id="a" provider-type="iptv",A
http://example.com/A.m3u8"#));
parser.parse().unwrap();
Source

pub fn get_playlist(&mut self) -> M3uPlaylist

Get the parsed M3uPlaylist, and you can continue the next parsing

Example:

use mediastream_rs::Parser;
use std::io::Cursor;

let mut parser = Parser::new(Cursor::new(r#"
#EXTM3U x-tvg-url="test"
#EXTINF:1 tvg-id="a" provider-type="iptv",A
http://example.com/A.m3u8"#));
parser.parse().unwrap();
_ = parser.get_playlist();
Source

pub fn into_inner(self) -> T

Return the inner reader

Example:

use mediastream_rs::Parser;
use std::io::Cursor;

let mut parser = Parser::new(Cursor::new(r#"
#EXTM3U x-tvg-url="test"
#EXTINF:1 tvg-id="a" provider-type="iptv",A
http://example.com/A.m3u8"#));

let _the_cursor = parser.into_inner();

Auto Trait Implementations§

§

impl<T> Freeze for Parser<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Parser<T>
where T: RefUnwindSafe,

§

impl<T> Send for Parser<T>
where T: Send,

§

impl<T> Sync for Parser<T>
where T: Sync,

§

impl<T> Unpin for Parser<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Parser<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Parser<T>
where T: UnwindSafe,

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