Get the latest tech news

Writing into Uninitialized Buffers in Rust


buffers in Rust Posted on Uninitialized buffers in Rust are a long-standing question, for example: - https://rust-lang.github.io/rfcs/2930-read-buf.html - https://doc.rust-lang.org/nightly/unstable-book/library-features/core-io-borrowed-buf.html - https://blog.yoshuawuyts.com/uninit-read-write/ - https://internals.rust-lang.org/t/reading-into-uninitialized-buffers-yet-again/13282/4 Recently, John Nunley and Alex Saveau came up with an idea for a new approach, using a Buffer trait, which is now in rustix 1.0, which I'll describe in this post. Update: This idea is now available in a standalone published library: buffer-trait.

Buffer uses a type parameter T rather than hard-coding u8, so that it can be used by functions like epoll::wait, kevent, and port::get to return event records instead of bytes. Rust's std currently contains an experimental API based on BorrowedBuf, which has the nice property of allowing users to use it without using unsafe, and without doing anything hugely inefficient, such as initializing the full buffer. The Buffer trait described here is simpler, avoiding the need for a "double cursor", however it does have an unsafe required method.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of Rust

Rust

Related news:

News photo

Show HN: Stack Error – ergonomic error handling for Rust

News photo

'Rust is So Good You Can Get Paid $20K to Make It as Fast as C'

News photo

Show HN: Model2vec-Rs – Fast Static Text Embeddings in Rust