1
0
Fork 0
mirror of https://github.com/sile/hls_m3u8.git synced 2024-05-18 16:28:20 +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;
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, PartialOrd, Ord, Hash)]
#[derive(Clone, Debug)]
pub(crate) struct AttributePairs<'a> {
string: &'a str,
index: usize,

View file

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