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

Deprecates Pointer::split_at, adds Pointer::split_at_offset #89

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

chanced
Copy link
Owner

@chanced chanced commented Oct 21, 2024

Solves #88

  • Deprecates Pointer::split_at
  • Adds Pointer::split_at_offset

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 99.1%. Comparing base (c694765) to head (290d650).

Files with missing lines Patch % Lines
src/pointer.rs 50.0% 2 Missing ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
src/pointer.rs 98.0% <50.0%> (-0.3%) ⬇️

@@ -233,7 +233,37 @@ impl Pointer {
/// assert_eq!(tail, Pointer::from_static("/bar/baz"));
/// assert_eq!(ptr.split_at(3), None);
/// ```
#[deprecated(
since = "0.8.0",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we do 0.7 already?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lol, no. I skipped ahead. Thanks!

/// assert_eq!(tail, Pointer::from_static("/bar/baz"));
/// assert_eq!(ptr.split_at_offset(3), None);
/// ```
pub fn split_at_offset(&self, offset: usize) -> Option<(&Self, &Self)> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is safe because it returns an Option, but should we maybe make it unsafe (and not check the boundary condition)?

I imagine that one either will have a valid offset to use already, or they'll use split_at instead. Seems unlikely they'll try some offset they're unsure is correct.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept the signature the same as split_at assuming we'd deprecate it and phase it out. Then perhaps re-introduce it using the position instead.

I'm truly not sure why I opted to go for offset in hindsight. It's like I spaced on the fact that I had get etc that were index based. Rather annoying mistake on my part.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about adding split_at_offset_unchecked? The reason I'm hesitant is solely for crates that avoid unsafe entirely.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm truly not sure why I opted to go for offset in hindsight. It's like I spaced on the fact that I had get etc that were index based. Rather annoying mistake on my part.

Don't beat yourself over it, it wasn't as obvious back then. I also didn't realise we could extend the get method to achieve what we really wanted to do with that; if I had, I'd have pushed back more.

What about adding split_at_offset_unchecked? The reason I'm hesitant is solely for crates that avoid unsafe entirely.

Those can opt to use split_at ;)

Unless your concern is over a lack of alternative in the interim? I suppose we can also keep split_at_offset with the current signature, though we'd probably deprecate it too longer term. Feels a bit odd to add something we may remove later, but I think it makes sense in this case.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. Good points. You're right that it is odd - especially if we don't end up spacing the releases.


### Changed

- Changed signature of `PathBuf::parse` to avoid requiring allocation.
- Bumps minimum Rust version to 1.79.
- `Pointer::get` now accepts ranges and can produce `Pointer` segments as output (similar to
`slice::get`).
- Deprecates `Pointer::split_at`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deprecated can have its own section.

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.

3 participants