mirror of
https://github.com/sile/hls_m3u8.git
synced 2024-11-26 09:00:58 +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;
|
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,
|
||||||
|
|
12
src/line.rs
12
src/line.rs
|
@ -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,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue