Skip to content
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

Document KnownLayout #988

Merged
merged 1 commit into from
Mar 1, 2024
Merged

Document KnownLayout #988

merged 1 commit into from
Mar 1, 2024

Conversation

jswrenn
Copy link
Collaborator

@jswrenn jswrenn commented Mar 1, 2024

Documents the derive, and aligns the trait documentation with that of other traits.

@jswrenn jswrenn enabled auto-merge March 1, 2024 18:14
src/lib.rs Outdated
/// # Limitations
///
/// This derive cannot currently be applied to unsized structs with the
/// default-`repr`.
Copy link
Member

Choose a reason for hiding this comment

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

Not sure that "default-repr" is a standard term. Maybe "without an explicit repr attribute" or something?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

src/lib.rs Outdated
/// internals of this crate.
/// Implements [`KnownLayout`].
///
/// This derive analyzes various qualities of a type's layout that are needed
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// This derive analyzes various qualities of a type's layout that are needed
/// This derive analyzes various properties of a type's layout that are needed

Alternatively, "aspects"?

Same below in the other doc comment.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

src/lib.rs Outdated
/// Implements [`KnownLayout`].
///
/// This derive analyzes various qualities of a type's layout that are needed
/// for some of zerocopy's APIs. It should be used whenver possible, and can be
Copy link
Member

Choose a reason for hiding this comment

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

Should we be suggesting "use this whenever possible", or just leave it up to users to discover (via bounds) when they need to derive it? It seems redundant given that the bounds will guide them to when they need to derive KnownLayout. It adds extra prose that, to me, sounds a tad mystical.

Same elsewhere in this PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nixed the "use this whenever possible"; I agree it sounds a bit mystical here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That said, I'd like to keep it in the crate-level overview.

Documents the derive, and aligns the trait documentation with that
of other traits.
Copy link
Member

@joshlf joshlf left a comment

Choose a reason for hiding this comment

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

It might be worth explicitly calling out that this supports unsized slice DST types, and providing examples in the documentation. We'll have to be a bit careful because:

  • We also require KnownLayout on Sized types, so we shouldn't imply that that's the only time when it's needed.
  • We may make KnownLayout smarter in the future and use it encode other information that lets us do things besides slice DST stuff.

That said, I could imagine someone thinking, "why do you need this if you have mem::size_of and mem::align_of?", and it could be good to respond to that thought.

Copy link
Member

@joshlf joshlf left a comment

Choose a reason for hiding this comment

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

It might be worth explicitly calling out that this supports unsized slice DST types, and providing examples in the documentation. We'll have to be a bit careful because:

  • We also require KnownLayout on Sized types, so we shouldn't imply that that's the only time when it's needed.
  • We may make KnownLayout smarter in the future and use it encode other information that lets us do things besides slice DST stuff.

That said, I could imagine someone thinking, "why do you need this if you have mem::size_of and mem::align_of?", and it could be good to respond to that thought.

Discussed offline; will follow up in #993

@jswrenn jswrenn added this pull request to the merge queue Mar 1, 2024
Merged via the queue into main with commit 1bf6212 Mar 1, 2024
210 checks passed
@jswrenn jswrenn deleted the doc-knownlayout branch March 1, 2024 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants