1
0
Fork 0
mirror of https://github.com/sile/hls_m3u8.git synced 2024-11-22 15:21:01 +00:00

improve Iterator types

This commit is contained in:
Luro02 2020-02-06 17:02:44 +01:00
parent 5de47561b1
commit 66c0b8dd0c
No known key found for this signature in database
GPG key ID: B66FD4F74501A9CF
2 changed files with 5 additions and 9 deletions

View file

@ -1,6 +1,6 @@
use core::iter::FusedIterator; use core::iter::FusedIterator;
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, PartialOrd, Ord, Hash)] #[derive(Clone, Debug)]
pub(crate) struct AttributePairs<'a> { pub(crate) struct AttributePairs<'a> {
string: &'a str, string: &'a str,
index: usize, index: usize,

View file

@ -5,11 +5,9 @@ use std::str::FromStr;
use crate::tags; use crate::tags;
use crate::Error; use crate::Error;
#[derive(Debug, Clone, PartialEq, PartialOrd, Ord, Eq, Hash)] #[derive(Debug, Clone)]
pub(crate) struct Lines<'a> { pub(crate) struct Lines<'a> {
buffer: &'a str, lines: ::core::str::Lines<'a>,
// the line at which the iterator currently is
position: usize,
} }
impl<'a> Iterator for Lines<'a> { impl<'a> Iterator for Lines<'a> {
@ -19,9 +17,8 @@ impl<'a> Iterator for Lines<'a> {
let mut stream_inf = false; let mut stream_inf = false;
let mut stream_inf_line = None; let mut stream_inf_line = None;
for line in self.buffer.lines().skip(self.position) { while let Some(line) = self.lines.next() {
let line = line.trim(); let line = line.trim();
self.position += 1;
if line.is_empty() { if line.is_empty() {
continue; continue;
@ -62,8 +59,7 @@ impl<'a> Iterator for Lines<'a> {
impl<'a> From<&'a str> for Lines<'a> { impl<'a> From<&'a str> for Lines<'a> {
fn from(buffer: &'a str) -> Self { fn from(buffer: &'a str) -> Self {
Self { Self {
buffer, lines: buffer.lines(),
position: 0,
} }
} }
} }