mirror of
https://github.com/sile/hls_m3u8.git
synced 2024-11-22 07:10:59 +00:00
improve Iterator types
This commit is contained in:
parent
5de47561b1
commit
66c0b8dd0c
2 changed files with 5 additions and 9 deletions
|
@ -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,
|
||||
|
|
12
src/line.rs
12
src/line.rs
|
@ -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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue