Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal for Walk / WalkMut #83

Closed
wants to merge 1 commit into from
Closed

Proposal for Walk / WalkMut #83

wants to merge 1 commit into from

Conversation

chanced
Copy link
Owner

@chanced chanced commented Oct 20, 2024

The

pub trait Walk: Resolve<Error: Debug> {
    type WalkTo<'value, 'ptr>;    
    type WalkFrom<'value>;
    fn walk_to<'v, 'p>(&'v self, to: &'p Pointer) -> Self::WalkTo<'v, 'p>;
    fn walk_from(&self, from: PointerBuf) -> Result<Self::WalkFrom<'_>, Self::Error>;
    fn walk(&self) -> Self::WalkFrom<'_> {
        self.walk_from(PointerBuf::default()).unwrap()
    }
}
pub trait WalkMut: ResolveMut<Error: Debug> {
    type WalkTo<'value, 'ptr>;    
    type WalkFrom<'value>;
    fn walk_to_mut<'v, 'p>(&'v mut self, to: &'p Pointer) -> Self::WalkTo<'v, 'p>;
    fn walk_from_mut(&mut self, from: PointerBuf) -> Result<Self::WalkFrom<'_>, Self::Error>;
    fn walk_mut(&mut self) -> Self::WalkFrom<'_> {
        self.walk_from_mut(PointerBuf::default()).unwrap()
    }
}

Each iterator returns the full path of the value along with a (mut) reference to the current node.

In the case of WalkTo, the iterator follows the path of the Pointer, emitting the result of resolve of each token as if the full path were resolved.

For WalkFrom, it walks a Value from a given Pointer onward, emitting the full path (as a PathBuf) for each node.

I have WalkTo implemented. WalkFrom I have a previous implementation specific to JSON that I can make generic. I haven't bothered with mut of either.

This could be far too niche to bother. As such I'll hold off on finishing it.

@asmello let me know what you think.

@chanced
Copy link
Owner Author

chanced commented Oct 20, 2024

as discussed in #42

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 88.38384% with 23 lines in your changes missing coverage. Please review.

Project coverage is 98.4%. Comparing base (ccef032) to head (6801060).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/walk.rs 93.4% 12 Missing ⚠️
src/pointer.rs 0.0% 9 Missing ⚠️
src/resolve.rs 71.4% 2 Missing ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
src/resolve.rs 99.5% <71.4%> (-0.5%) ⬇️
src/pointer.rs 97.5% <0.0%> (-0.7%) ⬇️
src/walk.rs 93.4% <93.4%> (ø)

@chanced
Copy link
Owner Author

chanced commented Oct 20, 2024

As of right now, this doesn't seem like the right abstractions for this crate.

I'm going to leave this open for now incase any users would like to chime in on ideas or needs for similar abstractions.

@chanced
Copy link
Owner Author

chanced commented Oct 21, 2024

On second thought, this is about to become completely obsolete with get now accepting ranges. Any iterator built with similar intent from here on out should be a lot cleaner.

@chanced chanced closed this Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants