chanced / jsonptr

JSON Pointer (RFC 6901) implementation for Rust
Apache License 2.0
44 stars 4 forks source link

Slicing API for `Pointer` #84

Closed asmello closed 2 weeks ago

asmello commented 2 weeks ago

Follow up of some ideas in #42.

This is effectively an extension of the split methods that can slice and dice Pointer types without allocation, similar to how slice::get works.

We use token indices as the range bounds, which ensures that any valid bound produces a valid &Pointer as a result.

This is not a breaking change.

codecov-commenter commented 2 weeks ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 99.2%. Comparing base (6630744) to head (4e67712).

Additional details and impacted files | [Files with missing lines](https://app.codecov.io/gh/chanced/jsonptr/pull/84?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Chance) | Coverage Δ | | |---|---|---| | [src/pointer.rs](https://app.codecov.io/gh/chanced/jsonptr/pull/84?src=pr&el=tree&filepath=src%2Fpointer.rs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Chance#diff-c3JjL3BvaW50ZXIucnM=) | `98.2% <100.0%> (-0.1%)` | :arrow_down: | | [src/pointer/slice.rs](https://app.codecov.io/gh/chanced/jsonptr/pull/84?src=pr&el=tree&filepath=src%2Fpointer%2Fslice.rs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Chance#diff-c3JjL3BvaW50ZXIvc2xpY2UucnM=) | `100.0% <100.0%> (ø)` | |
chanced commented 2 weeks ago

SliceIndex did work!? That's awesome! You are damn good at this man.

I'm still on mobile, out and about, but I'll look at it tonight, hopefully.

chanced commented 2 weeks ago

Man, this language is awesome.

This solves #42. We already have a way to get a token by index, this allows for the rest (splitting, ranging, etc). Moving forward, we can reference tokens by index or range if we ever add additional nice-to-have methods.

42 covered more than the range or being able to split at tokens. I'm going to split off a couple more tickets from it and reduce it down to simply being able to split at an index.

asmello commented 2 weeks ago

SliceIndex did work!? That's awesome! You are damn good at this man.

Nope, it didn't! You weren't wrong about that remark, it's just that we're not actually meant to implement SliceIndex (it's even a sealed trait, for good reason). I introduced our own trait instead.

Man, this language is awesome.

I tend to agree, it's pretty neat I was able to express what I wanted with the trait system.

asmello commented 2 weeks ago

Looking again I think SlicePointer is a bit awkward as a name, I meant it as "you slice a pointer with it", but that's probably not how most people will read it. PointerSlice probably makes more sense. Will follow up with a quick rename before we release.

asmello commented 2 weeks ago

Actually, I'm thinking about it all wrong. It's SliceIndex, so it should be PointerIndex, duh.