Skip to content

Tracking Issue for core_io_borrowed_buf #117693

New issue

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

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

Already on GitHub? # to your account

Open
2 of 4 tasks
jmillikin opened this issue Nov 8, 2023 · 8 comments
Open
2 of 4 tasks

Tracking Issue for core_io_borrowed_buf #117693

jmillikin opened this issue Nov 8, 2023 · 8 comments
Labels
C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@jmillikin
Copy link
Contributor

jmillikin commented Nov 8, 2023

Feature gate: #![feature(core_io_borrowed_buf)]

This is a tracking issue for an MVP of core::io, which contains an OS-independent subset of std::io.

Public API

The initial API of this module consists of BorrowedBuf and BorrowedCursor, which were previously only available in std.

Steps / History

Unresolved Questions

  • None yet.

Footnotes

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html

@jmillikin jmillikin added C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Nov 8, 2023
@jmillikin jmillikin changed the title Tracking Issue for core::io Tracking Issue for core_io_borrowed_buf Nov 8, 2023
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Nov 8, 2023
…m-ou-se

Move `BorrowedBuf` and `BorrowedCursor` from `std:io` to `core::io`

Tracking issue: rust-lang#117693

ACP: rust-lang/libs-team#290
TaKO8Ki added a commit to TaKO8Ki/rust that referenced this issue Nov 9, 2023
…m-ou-se

Move `BorrowedBuf` and `BorrowedCursor` from `std:io` to `core::io`

Tracking issue: rust-lang#117693

ACP: rust-lang/libs-team#290
TaKO8Ki added a commit to TaKO8Ki/rust that referenced this issue Nov 9, 2023
…m-ou-se

Move `BorrowedBuf` and `BorrowedCursor` from `std:io` to `core::io`

Tracking issue: rust-lang#117693

ACP: rust-lang/libs-team#290
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Nov 9, 2023
Rollup merge of rust-lang#117694 - jmillikin:core-io-borrowed-buf, r=m-ou-se

Move `BorrowedBuf` and `BorrowedCursor` from `std:io` to `core::io`

Tracking issue: rust-lang#117693

ACP: rust-lang/libs-team#290
cpu added a commit to cpu/rustls-ffi that referenced this issue Nov 15, 2023
Unbreaks builds using the read_buf feature.
Tracking issue: rust-lang/rust#117693
@tgross35
Copy link
Contributor

tgross35 commented Feb 26, 2024

These types in core could use a core::fmt::Write impl, but I am not sure how this is possible without conflicting with the blanket impl for std::io::Write.

@taralx
Copy link
Contributor

taralx commented Mar 16, 2024

Is the intent to stabilize this at the same time as #78485 or independently of it?

@kornelski
Copy link
Contributor

kornelski commented Jun 5, 2024

I'm surprised that this doesn't have any safe integration with Vec. I'd like to have vec.as_borrowed_buf() that can safely append to the uninitialized capacity, without having to manually perform unsafe vec.set_len correction afterwards.

@keepsimple1

This comment was marked as resolved.

@keepsimple1
Copy link

keepsimple1 commented Aug 13, 2024

If I understand, BorrowedBuf (like MaybeUninit) essentially is safe to write, may I suggest adding a method to the API of BorrowedBuf:

/// Copies the bytes of `buf` to self starting at `offset`.
///  Returns the number of bytes actually written.
///
/// If `offset` is equal or larger than `self.buf.len()`, returns 0.
/// If `offset` is larger than `self.init`, the region `self.buf[self.init..offset]` is zeroed. 
pub fn write(&mut self, offset: usize, buf: &[u8]) -> usize

(this method updates filled and init accordingly)

The idea is to make the API even easier to use:

  • Simpler: no need to use BorrowedCursor for such use cases.
  • No need to use different APIs to write filled / init section and uninit sections.
  • No panics (from this method) as it returns the written length.
  • Compatible with existing API.

What do you think?

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 25, 2024
Add BorrowedBuf::into_filled{,_mut} methods to allow returning buffer with original lifetime

See rust-lang/libs-team#473 and tracking issue rust-lang#117693.
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Nov 25, 2024
Rollup merge of rust-lang#132533 - SUPERCILEX:patch-4, r=Mark-Simulacrum

Add BorrowedBuf::into_filled{,_mut} methods to allow returning buffer with original lifetime

See rust-lang/libs-team#473 and tracking issue rust-lang#117693.
@hxuhack
Copy link

hxuhack commented Mar 24, 2025

According to the source code, Capacity() returns self.filled, which appears inconsistent with the descriptions of capacity, filled, and initialized.

@yoshuawuyts
Copy link
Member

.@sunfishcode wrote about an alternative to the BorrowedBuf APIs in Writing into uninitialized buffers in Rust. The design outlined there is based on the APIs used in bytecodealliance/rustix, and is based on a new trait Buffer that can abstract over both e.g. Vec<T> and &mut [MaybeUninit<T>].

While this tracking issue is not the right avenue to discuss the tradeoffs and differences between the two APIs 1, I wanted to make sure that it was mentioned on this tracking issue. It seems like a credible alternative to the BorrowedBuf API, and I believe it's worth considering going forward. Or at the very least: the blog post is well worth a read.

Footnotes

  1. Zulip would be a better avenue for that. I don't believe there is a thread yet, but anyone is free to start one if they want to.

@briansmith
Copy link
Contributor

  1. Zulip would be a better avenue for that. I don't believe there is a thread yet, but anyone is free to start one if they want to.

There are three threads, two of them are old:

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

8 participants