how best to skip comments?

Open
#460 3 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
rust
Domain
backend

Research direction

Start by reading the Reader event APIs and the comment handling paths in the repository; the issue does not name files or tests. Compare buffered and unbuffered reading to identify a pattern for skipping comment events, then check whether the approach preserves the reader’s input and buffer constraints. Done means providing a workable way to ignore comments during buffered reading.

Written by the indexing model from the issue text.

Description

enhancement help wanted

I'm looking at porting some applications from xml-rs to quick-xml, and one of the blockers I've hit is that quick_xml doesn't have a way to quickly strip all comments (à la xml-rs's ParserConfig::ignore_comments(true)).

A wrapper function like

fn read_event<'a, 'b, R: BufRead>(
    reader: &'a mut Reader<R>,
    buf: &'b mut Vec<u8>,
) -> Result<Event<'b>> {
    loop {
        let event = reader.read_event(buf)?;
        if !matches!(event, Event::Comment(_)) {
            return Ok(event);
        }
    }
}

seems appealing but of course doesn't work because of our friend

`*buf` was mutably borrowed here in the previous iteration of the loop

Switching to read_event_unbuffered and requiring the input to be &[u8] works but isn't ideal.

Are there any good patterns for ignoring comments?

Dominant language
Rust
Stars
1.6k
Forks
299
Avg merge
2d 4h
Merged PRs (30d)
9

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from tafia/quick-xml

All issues in tafia/quick-xml

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.