mirror of
https://github.com/rutgersc/m3u8-rs.git
synced 2024-12-31 18:28:40 +00:00
Fix doc tests
This commit is contained in:
parent
e3d0cb8cff
commit
7583aaccba
1 changed files with 50 additions and 42 deletions
92
src/lib.rs
92
src/lib.rs
|
@ -12,23 +12,25 @@
|
||||||
//! use nom::IResult;
|
//! use nom::IResult;
|
||||||
//! use std::io::Read;
|
//! use std::io::Read;
|
||||||
//!
|
//!
|
||||||
//! let mut file = std::fs::File::open("playlist.m3u8").unwrap();
|
//! fn main() {
|
||||||
//! let mut bytes: Vec<u8> = Vec::new();
|
//! let mut file = std::fs::File::open("playlist.m3u8").unwrap();
|
||||||
//! file.read_to_end(&mut bytes).unwrap();
|
//! let mut bytes: Vec<u8> = Vec::new();
|
||||||
|
//! file.read_to_end(&mut bytes).unwrap();
|
||||||
//!
|
//!
|
||||||
//! // Option 1: fn parse_playlist_res(input) -> Result<Playlist, _>
|
//! // Option 1: fn parse_playlist_res(input) -> Result<Playlist, _>
|
||||||
//! match m3u8_rs::parse_playlist_res(&bytes) {
|
//! match m3u8_rs::parse_playlist_res(&bytes) {
|
||||||
//! Ok(Playlist::MasterPlaylist(pl)) => println!("Master playlist:\n{:?}", pl),
|
//! Ok(Playlist::MasterPlaylist(pl)) => println!("Master playlist:\n{:?}", pl),
|
||||||
//! Ok(Playlist::MediaPlaylist(pl)) => println!("Media playlist:\n{:?}", pl),
|
//! Ok(Playlist::MediaPlaylist(pl)) => println!("Media playlist:\n{:?}", pl),
|
||||||
//! Err(e) => println!("Error: {:?}", e)
|
//! Err(e) => println!("Error: {:?}", e)
|
||||||
//! }
|
//! }
|
||||||
//!
|
//!
|
||||||
//! // Option 2: fn parse_playlist(input) -> IResult<_, Playlist, _>
|
//! // Option 2: fn parse_playlist(input) -> IResult<_, Playlist, _>
|
||||||
//! match m3u8_rs::parse_playlist(&bytes) {
|
//! match m3u8_rs::parse_playlist(&bytes) {
|
||||||
//! IResult::Done(i, Playlist::MasterPlaylist(pl)) => println!("Master playlist:\n{:?}", pl),
|
//! IResult::Done(i, Playlist::MasterPlaylist(pl)) => println!("Master playlist:\n{:?}", pl),
|
||||||
//! IResult::Done(i, Playlist::MediaPlaylist(pl)) => println!("Media playlist:\n{:?}", pl),
|
//! IResult::Done(i, Playlist::MediaPlaylist(pl)) => println!("Media playlist:\n{:?}", pl),
|
||||||
//! IResult::Error(e) => panic!("Parsing error: \n{}", e),
|
//! IResult::Error(e) => panic!("Parsing error: \n{}", e),
|
||||||
//! IResult::Incomplete(e) => panic!("Parsing error: \n{:?}", e),
|
//! IResult::Incomplete(e) => panic!("Parsing error: \n{:?}", e),
|
||||||
|
//! }
|
||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
|
@ -40,12 +42,14 @@
|
||||||
//! use std::io::Read;
|
//! use std::io::Read;
|
||||||
//! use nom::IResult;
|
//! use nom::IResult;
|
||||||
//!
|
//!
|
||||||
//! let mut file = std::fs::File::open("masterplaylist.m3u8").unwrap();
|
//! fn main() {
|
||||||
//! let mut bytes: Vec<u8> = Vec::new();
|
//! let mut file = std::fs::File::open("masterplaylist.m3u8").unwrap();
|
||||||
//! file.read_to_end(&mut bytes).unwrap();
|
//! let mut bytes: Vec<u8> = Vec::new();
|
||||||
//!
|
//! file.read_to_end(&mut bytes).unwrap();
|
||||||
//! if let IResult::Done(_, pl) = m3u8_rs::parse_master_playlist(&bytes) {
|
//!
|
||||||
//! println!("{}", pl);
|
//! if let IResult::Done(_, pl) = m3u8_rs::parse_master_playlist(&bytes) {
|
||||||
|
//! println!("{:?}", pl);
|
||||||
|
//! }
|
||||||
//! }
|
//! }
|
||||||
//!
|
//!
|
||||||
//! ```
|
//! ```
|
||||||
|
@ -53,30 +57,34 @@
|
||||||
//! Creating a playlist and writing it back to a vec/file
|
//! Creating a playlist and writing it back to a vec/file
|
||||||
//!
|
//!
|
||||||
//! ```
|
//! ```
|
||||||
|
//! extern crate m3u8_rs;
|
||||||
|
//! use m3u8_rs::playlist::{MediaPlaylist, MediaPlaylistType, MediaSegment};
|
||||||
//!
|
//!
|
||||||
//! let playlist = MediaPlaylist {
|
//! fn main() {
|
||||||
//! version: 6,
|
//! let playlist = MediaPlaylist {
|
||||||
//! target_duration: 3.0,
|
//! version: 6,
|
||||||
//! media_sequence: 338559,
|
//! target_duration: 3.0,
|
||||||
//! discontinuity_sequence: 1234,
|
//! media_sequence: 338559,
|
||||||
//! end_list: true,
|
//! discontinuity_sequence: 1234,
|
||||||
//! playlist_type: Some(MediaPlaylistType::Vod),
|
//! end_list: true,
|
||||||
//! segments: vec![
|
//! playlist_type: Some(MediaPlaylistType::Vod),
|
||||||
//! MediaSegment {
|
//! segments: vec![
|
||||||
//! uri: "20140311T113819-01-338559live.ts".into(),
|
//! MediaSegment {
|
||||||
//! duration: 2.002,
|
//! uri: "20140311T113819-01-338559live.ts".into(),
|
||||||
//! title: Some("title".into()),
|
//! duration: 2.002,
|
||||||
//! ..Default::default()
|
//! title: Some("title".into()),
|
||||||
//! },
|
//! ..Default::default()
|
||||||
//! ],
|
//! },
|
||||||
//! ..Default::default()
|
//! ],
|
||||||
//! };
|
//! ..Default::default()
|
||||||
|
//! };
|
||||||
//!
|
//!
|
||||||
//! let mut v: Vec<u8> = Vec::new();
|
//! //let mut v: Vec<u8> = Vec::new();
|
||||||
//! playlist_original.write_to(&mut v).unwrap();
|
//! //playlist.write_to(&mut v).unwrap();
|
||||||
//!
|
//!
|
||||||
//! let mut file = std::fs::File::open("playlist.m3u8").unwrap();
|
//! //let mut file = std::fs::File::open("playlist.m3u8").unwrap();
|
||||||
//! playlist_original.write_to(&mut file).unwrap();
|
//! //playlist.write_to(&mut file).unwrap();
|
||||||
|
//! }
|
||||||
//!
|
//!
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue