Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5fd7738

Browse filesBrowse files
committed
Remove redundant index field from tree::Parser
1 parent 78ff333 commit 5fd7738
Copy full SHA for 5fd7738

File tree

Expand file treeCollapse file tree

1 file changed

+6
-10
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+6
-10
lines changed

‎usb_hid_item/src/tree.rs

Copy file name to clipboardExpand all lines: usb_hid_item/src/tree.rs
+6-10Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ use {
77

88
#[derive(Debug)]
99
pub struct Parser<'a> {
10-
// Splitting the fields and manually reconstructing the item parser allows
11-
// avoiding troubles with shared mutable references, lifetimes etc.
12-
data: &'a [u8],
13-
index: Cell<usize>,
10+
// Manually reconstructing the item parser allows avoiding troubles with shared mutable
11+
// references, lifetimes etc.
12+
data: Cell<&'a [u8]>,
1413
}
1514

1615
impl<'a> Parser<'a> {
@@ -74,14 +73,14 @@ impl<'a, 'p> Iterator for StackFrame<'a, 'p> {
7473

7574
fn next(&mut self) -> Option<Self::Item> {
7675
let mut it = super::Parser {
77-
data: self.inner.data.get(self.inner.index.get()..)?,
76+
data: self.inner.data.get(),
7877
};
7978
loop {
8079
let item = match it.next()? {
8180
Ok(e) => e,
8281
Err(e) => return Some(Err(ParseError::from_item(e))),
8382
};
84-
self.inner.index.set(self.inner.data.len() - it.data.len());
83+
self.inner.data.set(it.data);
8584
match item {
8685
Item::Collection(ty) => break Some(Ok(Value::Collection(ty))),
8786
Item::EndCollection => break Some(Ok(Value::EndCollection)),
@@ -243,10 +242,7 @@ impl Field {
243242
}
244243

245244
pub fn parse(data: &[u8]) -> Parser<'_> {
246-
Parser {
247-
data,
248-
index: Default::default(),
249-
}
245+
Parser { data: data.into() }
250246
}
251247

252248
#[cfg(test)]

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.