Skip to content

Trim BorrowedCursor API #143829

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

a1phyr
Copy link
Contributor

@a1phyr a1phyr commented Jul 12, 2025

This PR removes some method from the unstable BorrowedCursor type. A rational for each change can be found in the message of each commit.

I don't think that an ACP is required for this, please tell me if it is not the case.

Cc #78485 #117693

a1phyr added 3 commits July 9, 2025 18:11
This method was not really useful: at no point one would only need to
read the initialized part of the cursor without mutating it.
I assume that this method was there for completeness, but there is
hardly any useful use of it: the buffer it gave was not always connected
to the start of the cursor and its use required `unsafe` anyway to mark
the bytes as initialized.
This enable removing the `start` field, so `BorrowedCursor` fits in a
single register. Because `written` is almost always used in difference
with another call, this changes nothing else in practice.
@rustbot
Copy link
Collaborator

rustbot commented Jul 12, 2025

r? @scottmcm

rustbot has assigned @scottmcm.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jul 12, 2025
@joshtriplett joshtriplett added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. I-libs-api-nominated Nominated for discussion during a libs-api team meeting. labels Jul 13, 2025
@joshtriplett
Copy link
Member

joshtriplett commented Jul 13, 2025

I'm surprised by the removal of init_ref(); I'd expect that to be a common need.

@a1phyr
Copy link
Contributor Author

a1phyr commented Jul 13, 2025

Why for? It gives read-only bytes that you're not supposed to read, just like the buffer of Read::read method. You were maybe thinking of filled bytes, which the API purposefully does not give access to (and the reason of #142885)?

@scottmcm
Copy link
Member

I don't think me as a reviewer is the right people to make choices here. Feels like more an unresolved question on a tracking issue -- after all, one can always stabilize a subset and decide whether to remove methods later.

r? libs-api

@rustbot rustbot assigned m-ou-se and unassigned scottmcm Jul 13, 2025
@joshtriplett
Copy link
Member

Why for? It gives read-only bytes that you're not supposed to read, just like the buffer of Read::read method. You were maybe thinking of filled bytes

Yes, I was, thank you.

@the8472
Copy link
Member

the8472 commented Jul 15, 2025

We discussed this during today's libs-api meeting. The changes look ok and we agree with the motivations.

But there have been some recent requests to make further changes to the API that you might be interested in:
#t-libs > Future of read_buf
#t-libs > BorrowedBuf/BorrowedCursor optimized for past, not future

@the8472 the8472 removed the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Jul 15, 2025
@ChrisDenton
Copy link
Member

The implementation and test changes look good to me

@bors r+

@bors
Copy link
Collaborator

bors commented Jul 15, 2025

📌 Commit 65df668 has been approved by ChrisDenton

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 15, 2025
@a1phyr
Copy link
Contributor Author

a1phyr commented Jul 15, 2025

But there have been some recent requests to make further changes to the API that you might be interested in:

Thanks, I didn't know about the first one!

I have not sent a PR/ACP/Zulip thread yet (I don't know which you be right), but I have a draft of changing the init field a boolean, which further simplify the API: https://github.com/a1phyr/rust/tree/improve_buf_api

About accessing the filled bytes, forbidding it was does on purpose, but I think that reevaluating this idea might be interesting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants