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

Rephrase conversion methods' documentation to accommodate DSTs #1269

Merged
merged 1 commit into from
May 16, 2024
Merged

Conversation

jswrenn
Copy link
Collaborator

@jswrenn jswrenn commented May 15, 2024

This entails removing reference to both size_of and align_of, which cannot be invoked on slice DSTs.

src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated
/// length, alignment, or overflow checks fail, it returns `Err`.
/// This method attempts to return a reference to the prefix of `bytes`
/// reinterpreted as a `Self` with `count` trailing elements, and reference
/// to the preceeding bytes. If there are insufficient bytes, or if `bytes`
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
/// to the preceeding bytes. If there are insufficient bytes, or if `bytes`
/// to the remaining bytes. If there are insufficient bytes, or if `bytes`

Or something else, but "preceding" only works if this were a suffix cast.

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
/// length, alignment, or overflow checks fail, it returns `Err`.
/// This method attempts to return a reference to the suffix of `bytes`
/// reinterpreted as a `Self` with `count` trailing elements, and reference
/// to the preceeding bytes. If there are insufficient bytes, or if that
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
/// to the preceeding bytes. If there are insufficient bytes, or if that
/// to the preceding bytes. If there are insufficient bytes, or if that

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
/// If the bytes of `candidate` are a valid instance of `Self`, reads those
/// bytes as `Self`. If `candidate.len() < size_of::<Self>()` or the bytes
/// are not a valid instance of `Self`, this returns `Err`.
/// If `candidate.len() < size_of::<Self>()` or the bytes are not a valid
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
/// If `candidate.len() < size_of::<Self>()` or the bytes are not a valid
/// If `candidate.len() != size_of::<Self>()` or the bytes are not a valid

src/lib.rs Outdated
Comment on lines 2279 to 2281
/// This method attempts to return a reference to `bytes` interpreted as a
/// `Self`. If there are insufficient or excess bytes, or if `bytes` is not
/// aligned to `Self`'s alignment requirement, this returns `Err`.
Copy link
Member

Choose a reason for hiding this comment

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

Here I think the old wording - "valid length for Self" (although I'd say size instead of length) - makes more sense. "Insufficient or excess" implies that there's one correct size, but that's not true - there could be many correct sizes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

How could there be many correct sizes? Isn't this backed by a try_cast_into_no_leftover?

Copy link
Collaborator Author

@jswrenn jswrenn May 15, 2024

Choose a reason for hiding this comment

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

Ah, I see your point. There's only one correct size per DST length though.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah exactly

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

src/lib.rs Outdated
Comment on lines 2487 to 2489
/// This method attempts to return a reference to `bytes` interpreted as a
/// `Self`. If there are insufficient or excess bytes, or if `bytes` is not
/// aligned to `Self`'s alignment requirement, this returns `Err`.
Copy link
Member

Choose a reason for hiding this comment

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

Same here as above.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

src/lib.rs Outdated
/// bytes. If `bytes.len() < size_of::<Self>()` or `bytes` is not aligned to
/// `align_of::<Self>()`, this returns `Err`.
/// This method computes the largest possible size of `Self` that can fit in
/// the leading bytes of `candidate`, then attempts to return both a
Copy link
Collaborator Author

@jswrenn jswrenn May 15, 2024

Choose a reason for hiding this comment

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

Whoops, this shouldn't be "bytes of candidate".

"bytes of bytes" is awkward, so perhaps I'll rename bytes to source.

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
Comment on lines 2704 to 2705
/// `Self` with `count` trailing elements. If the length of `source` is not
/// a valid size of `Self`, or if `source` is not appropriately aligned,
Copy link
Member

Choose a reason for hiding this comment

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

"Valid size of Self" isn't the right condition when an explicit count is given.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

src/ref.rs Outdated
Comment on lines 441 to 442
/// the remaining bytes. If the length of `source` is not a valid size of
/// `T`, or if `source` is not appropriately aligned, this returns `Err`.
Copy link
Member

Choose a reason for hiding this comment

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

"Valid size of T" isn't the right condition when an explicit count is given.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

src/ref.rs Outdated
Comment on lines 648 to 649
/// the remaining bytes. If the length of `source` is not a valid size of
/// `T`, this returns `Err`.
Copy link
Member

Choose a reason for hiding this comment

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

"Valid size of T" isn't the right condition when an explicit count is given.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

src/ref.rs Outdated
/// This method attempts to return a `Ref` to the suffix of `source`
/// interpreted as a `T` with `count` trailing elements, and a reference to
/// the preceding bytes. If there are insufficient bytes, or if that suffix
/// of `source` is not appropriately aligned, this returns `Err`.
Copy link
Member

Choose a reason for hiding this comment

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

Alignment isn't required 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.

src/ref.rs Outdated
/// This method attempts to return a `Ref` to the prefix of `source`
/// interpreted as a `T` with `count` trailing elements, and a reference to
/// the remaining bytes. If there are insufficient bytes, or if `source` is
/// not appropriately aligned, this returns `Err`.
Copy link
Member

Choose a reason for hiding this comment

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

Alignment isn't required 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.

@joshlf joshlf enabled auto-merge May 16, 2024 20:40
@joshlf joshlf added this pull request to the merge queue May 16, 2024
Merged via the queue into main with commit c8ea4b3 May 16, 2024
210 checks passed
@joshlf joshlf deleted the dst-docs branch May 16, 2024 21:08
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.

2 participants