Restore a pause_at() method, but for NetDocReader.
This commit is contained in:
parent
81f67e240b
commit
5d0990658a
|
@ -228,13 +228,11 @@ impl RouterDesc {
|
|||
Section<'a, RouterKW>,
|
||||
Section<'a, RouterKW>,
|
||||
)> {
|
||||
use crate::util::*;
|
||||
use RouterKW::*;
|
||||
|
||||
// Parse everything up through the header.
|
||||
let mut reader = PauseAt::from_peekable(reader.iter(), |item| {
|
||||
item.is_ok_with_kwd_not_in(&[ROUTER, IDENTITY_ED25519])
|
||||
});
|
||||
let mut reader =
|
||||
reader.pause_at(|item| item.is_ok_with_kwd_not_in(&[ROUTER, IDENTITY_ED25519]));
|
||||
let header = ROUTER_HEADER_RULES.parse(&mut reader)?;
|
||||
|
||||
// Parse everything up to but not including the signature.
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
use crate::argtype::FromBytes;
|
||||
use crate::keyword::Keyword;
|
||||
use crate::util::PauseAt;
|
||||
use crate::{Error, Pos, Result};
|
||||
use std::cell::{Ref, RefCell};
|
||||
use std::str::FromStr;
|
||||
|
@ -539,4 +540,25 @@ impl<'a, K: Keyword> NetDocReader<'a, K> {
|
|||
pub fn iter(&mut self) -> &mut std::iter::Peekable<impl Iterator<Item = Result<Item<'a, K>>>> {
|
||||
&mut self.tokens
|
||||
}
|
||||
/// Return a PauseAt wrapper around the peekable iterator in this
|
||||
/// NetDocReader that reads tokens until it reaches an element where
|
||||
/// 'f' is true.
|
||||
pub fn pause_at<F>(&mut self, f: F) -> PauseAt<'_, impl Iterator<Item = Result<Item<'a, K>>>, F>
|
||||
where
|
||||
F: FnMut(&Result<Item<'a, K>>) -> bool,
|
||||
{
|
||||
PauseAt::from_peekable(&mut self.tokens, f)
|
||||
}
|
||||
/// Return a PauseAt wrapper around the peekable iterator in this
|
||||
/// NetDocReader that returns all items.
|
||||
#[allow(unused)]
|
||||
pub fn pauseable(
|
||||
&mut self,
|
||||
) -> PauseAt<
|
||||
'_,
|
||||
impl Iterator<Item = Result<Item<'a, K>>>,
|
||||
impl FnMut(&Result<Item<'a, K>>) -> bool,
|
||||
> {
|
||||
self.pause_at(|_| false)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue