Skip to content

Use Iterator trait for going through items #3

@kaleidawave

Description

@kaleidawave

The problem with the Iterator trait is the type of Item. It has to be owned and cannot have a lifetime based on the &mut self item. This means that it cannot return the chain as an item.

The problem is that the result is owned. Here we want item1 to be usable, but chain be moved/unusable etc?

let mut iterator = json_iterator(r#"{ "key1": 2, "key2": "example" } "#);
let (chain, item1) = iterator.next();
let (chain, item2) = iterator.next();

However could experiment with Rc<> and unsafe to see if something is possible here.

The other possibility is referencing a field on the iterator.

let mut iterator = json_iterator(r#"{ "key1": 2, "key2": "example" } "#);
let item1 = iterator.next();
let chain = iterator.chain();

let item2 = iterator.next();
let chain = iterator.chain();

So far the callback based design is fine. But if someone wants this I can investigate these options

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions