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

adds len and is_empty to Pointer #69

Merged
merged 2 commits into from
Sep 30, 2024
Merged

adds len and is_empty to Pointer #69

merged 2 commits into from
Sep 30, 2024

Conversation

chanced
Copy link
Owner

@chanced chanced commented Sep 30, 2024

Adds len and is_empty to Pointer.

@codecov-commenter
Copy link

codecov-commenter commented Sep 30, 2024

Codecov Report

Attention: Patch coverage is 92.10526% with 3 lines in your changes missing coverage. Please review.

Please upload report for BASE (main@4c71d51). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/pointer.rs 92.1% 3 Missing ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
src/pointer.rs 97.8% <92.1%> (ø)

@chanced
Copy link
Owner Author

chanced commented Sep 30, 2024

@asmello we had talked about adding len before so I'm just going to go ahead and merge this.

@chanced chanced merged commit 7d6cd24 into main Sep 30, 2024
20 checks passed
Copy link
Collaborator

@asmello asmello left a comment

Choose a reason for hiding this comment

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

Leaving a comment on docs we can fix later.

/// assert_eq!(ptr.len(), 11);
///
/// ```
pub fn len(&self) -> usize {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is sane. One can always do ptr.tokens().count() for the alternative definition of "length".

I see that you've copied the doc-comment from str::len. This is mostly accurate, since we do indeed just delegate to that method, but the semantics is not quite right. I think we could go with something simpler instead, along the lines of:

    /// This length expresses the byte count of the underlying string that represents the RFC 6091 Pointer. See also [`std::str::len`].

Although the caveat with char/graphemes applies, it's less important for us than the relationship with std::str.

@chanced
Copy link
Owner Author

chanced commented Sep 30, 2024 via email

@chanced
Copy link
Owner Author

chanced commented Sep 30, 2024

Ugh, I accidentally added them to both Pointer and PointerBuf.

It would be a breaking change to delete them from PointerBuf, right?

@chanced chanced mentioned this pull request Sep 30, 2024
@asmello
Copy link
Collaborator

asmello commented Oct 1, 2024

Ugh, I accidentally added them to both Pointer and PointerBuf.

It would be a breaking change to delete them from PointerBuf, right?

I did wonder. I don't think it is, because PointerBuf implements Deref<Target=Pointer>, so ptr.len() works regardless.

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