Skip to content

Conversation

@frank-king
Copy link

@frank-king frank-king commented Dec 22, 2025

This RFC introduces a Thin wrapper which thinifies a fat pointer of a DST by inlining its metadata.

Rendered.

Pre-RFC on Rust Internal Forum.

Important

When responding to RFCs, try to use inline review comments (it is possible to leave an inline review comment for the entire file at the top) instead of direct comments for normal comments and keep normal comments for procedural matters like starting FCPs.

This keeps the discussion more organized.


Now they can be rewritten as:
- `List<T>` -> `&Thin<[T]>`
- `ThinVec<T>`, technically `Box<(usize, Thin<[MaybeUninit<T>]>)>` (in representation)

Choose a reason for hiding this comment

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

It is unfortunate that we can't fit Vec into this representation, but I feel like custom DSTs could eventually make it work with Thin, so, I'm not too upset about it.

Copy link
Author

Choose a reason for hiding this comment

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

Do you mean making std::vec::Vec<T> a thin pointer? What's the advantage compared to the current representation?

Choose a reason for hiding this comment

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

Yeah, specifically the fact that there's no way to represent a partially initialised slice like a Vec in a generic way. It would be cool if Vec<T> were Box<PartiallyInitSlice<T>> and ThinVec<T> were Box<Thin<PartiallyInitSlice<T>>.

Copy link
Author

Choose a reason for hiding this comment

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

Can I understand the PartiallyInitSlice<T> as a [MaybeUninit<T>] with an extra metadata inited_len: uszie indicating the number of initialized elements in this slice? Sounds cool!

Copy link
Author

Choose a reason for hiding this comment

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

But that requires DST of mutable metadata, or it is not possible to implement a push method for an &mut PartiallyInitSlice<T>

Choose a reason for hiding this comment

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

Right, under this situation, you'd still need to be implementing stuff for &mut Box directly, but at least the types are compatible with Thin.

I don't treat any of this as a set-in-stone proposal; my main point is that Thin not working for Vec now doesn't mean it can't necessarily work in the future, just, it would require extra stuff we don't have yet. And so, it not working for Vec shouldn't mean Thin as-is needs any particular changes to account for that.

Copy link
Author

Choose a reason for hiding this comment

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

Agreed.

Copy link
Author

Choose a reason for hiding this comment

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

Probably I can add this point to the "Future possibility" section?

Choose a reason for hiding this comment

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

Yeah, feel free to reword any amount of what I said and add it to the RFC!

I think that maybe making the capacity of a vec part of the metadata could be a useful step toward allowing some kind of ArrayVec solution in libstd, or at least making array::IntoIter less redundant, but there are a lot of different paths and we're not sure what path we'll take. But in terms of generalising ThinVec, it seems promising.

@jieyouxu jieyouxu added T-lang Relevant to the language team, which will review and decide on the RFC. T-types Relevant to the types team, which will review and decide on the RFC. labels Dec 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-lang Relevant to the language team, which will review and decide on the RFC. T-types Relevant to the types team, which will review and decide on the RFC.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants