rfcs icon indicating copy to clipboard operation
rfcs copied to clipboard

Guarantee slice representation

Open cramertj opened this issue 10 months ago • 2 comments

This RFC guarantees the representation of &str and &[T] to be equivalent to a repr(C) struct containing a pointer and a length.

Rendered

cramertj avatar Feb 19 '25 00:02 cramertj

@workingjubilee

Nonetheless, I have a question: what code specifically do we want to enable with this choice? Is it Rust code or external over-FFI code? In the latter case, refusing to stabilize any parameter-passing or return-passing details would remain somewhat frustrating and makes this less of an improvement over the status quo.

My use-case is FFI code (specifically, autogenerated C++ interop). Rust code can usually rely on calls to .as_ptr/len, so the guarantees in this RFC are much less useful in Rust. I don't particularly care whether the by-value ABI is stable as I'm happy to pass slice references by-pointer in parameter and return values.

cramertj avatar Feb 19 '25 23:02 cramertj

Would be nice to also have this for Box<[T]> and Box<str>.

GoldsteinE avatar Feb 27 '25 13:02 GoldsteinE