m3u8-rs/examples/with_nom_result.rs

36 lines
1.1 KiB
Rust
Raw Normal View History

use m3u8_rs::Playlist;
2016-06-03 18:56:45 +00:00
use std::io::Read;
fn main() {
let mut file = std::fs::File::open("playlist.m3u8").unwrap();
let mut bytes: Vec<u8> = Vec::new();
file.read_to_end(&mut bytes).unwrap();
let parsed = m3u8_rs::parse_playlist(&bytes);
let playlist = match parsed {
2021-11-18 12:54:46 +00:00
Result::Ok((_i, playlist)) => playlist,
2021-10-18 09:41:28 +00:00
Result::Err(e) => panic!("Parsing error: \n{}", e),
2016-06-03 18:56:45 +00:00
};
match playlist {
Playlist::MasterPlaylist(pl) => println!("Master playlist:\n{:?}", pl),
Playlist::MediaPlaylist(pl) => println!("Media playlist:\n{:?}", pl),
2016-06-03 18:56:45 +00:00
}
}
2021-11-18 12:54:46 +00:00
#[allow(unused)]
2016-06-03 18:56:45 +00:00
fn main_alt() {
let mut file = std::fs::File::open("playlist.m3u8").unwrap();
let mut bytes: Vec<u8> = Vec::new();
file.read_to_end(&mut bytes).unwrap();
let parsed = m3u8_rs::parse_playlist(&bytes);
match parsed {
2021-11-18 12:54:46 +00:00
Result::Ok((_i, Playlist::MasterPlaylist(pl))) => println!("Master playlist:\n{:?}", pl),
Result::Ok((_i, Playlist::MediaPlaylist(pl))) => println!("Media playlist:\n{:?}", pl),
2021-10-18 09:41:28 +00:00
Result::Err(e) => panic!("Parsing error: \n{}", e),
2016-06-03 18:56:45 +00:00
}
}