mirror of
https://codeberg.org/icewind/vbsp.git
synced 2026-06-03 18:54:05 +02:00
impl IntoIterator for &Entities
This commit is contained in:
parent
28bdbf678d
commit
011260e360
1 changed files with 25 additions and 16 deletions
|
|
@ -26,29 +26,38 @@ impl fmt::Debug for Entities {
|
||||||
.fmt(f)
|
.fmt(f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub struct EntitiesIter<'a> {
|
||||||
|
buf: &'a str,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Iterator for EntitiesIter<'a> {
|
||||||
|
type Item = RawEntity<'a>;
|
||||||
|
|
||||||
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
|
let start = self.buf.find('{')?;
|
||||||
|
let end = start + self.buf[start..].find('}')?;
|
||||||
|
|
||||||
|
let out = &self.buf[start..end + 1];
|
||||||
|
|
||||||
|
self.buf = &self.buf[end + 1..];
|
||||||
|
|
||||||
|
Some(RawEntity { buf: out })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> IntoIterator for &'a Entities {
|
||||||
|
type Item = RawEntity<'a>;
|
||||||
|
|
||||||
|
type IntoIter = EntitiesIter<'a>;
|
||||||
|
|
||||||
|
fn into_iter(self) -> Self::IntoIter {
|
||||||
|
self.iter()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Entities {
|
impl Entities {
|
||||||
pub fn iter(&self) -> impl Iterator<Item = RawEntity<'_>> {
|
pub fn iter(&self) -> EntitiesIter {
|
||||||
struct Iter<'a> {
|
EntitiesIter {
|
||||||
buf: &'a str,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Iterator for Iter<'a> {
|
|
||||||
type Item = RawEntity<'a>;
|
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
|
||||||
let start = self.buf.find('{')?;
|
|
||||||
let end = start + self.buf[start..].find('}')?;
|
|
||||||
|
|
||||||
let out = &self.buf[start..end + 1];
|
|
||||||
|
|
||||||
self.buf = &self.buf[end + 1..];
|
|
||||||
|
|
||||||
Some(RawEntity { buf: out })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Iter {
|
|
||||||
buf: &self.entities,
|
buf: &self.entities,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue