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

[doc] TryFromBytes, IntoBytes aren't symmetrical #860

Merged
merged 1 commit into from
Feb 12, 2024
Merged

Conversation

joshlf
Copy link
Member

@joshlf joshlf commented Feb 10, 2024

I don't love how this is currently worded. I'd love suggestions on improving it.

Comment on lines +1184 to +1193
/// # `TryFromBytes` is not symmetrical with [`IntoBytes`]
///
/// There are some types which implement both `TryFromBytes` and [`IntoBytes`],
/// but for which `TryFromBytes` is not guaranteed to accept all byte sequences
/// produced by `IntoBytes`. In other words, for some `T: TryFromBytes +
/// IntoBytes`, there exist values of `t: T` such that
/// `TryFromBytes::try_from_ref(t.as_bytes()) == None`. Code should not
/// generally assume that values produced by `IntoBytes` will necessarily be
/// accepted as valid by `TryFromBytes`.
///
Copy link
Collaborator

Choose a reason for hiding this comment

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

Perhaps we could include an example here?

Copy link
Member Author

Choose a reason for hiding this comment

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

We're in a catch-22 here. We intend to eventually add IntoBytes impls for reference and pointer types, but we don't have them yet (#170). Once we have them, they will be described by this section. However, we can't wait to add this section because, if we do, people might write generic code that relies on the thing we're telling them not to rely on here, and that code would only break in the future once we add those impls.

@joshlf joshlf added this pull request to the merge queue Feb 12, 2024
Merged via the queue into main with commit eba9dd2 Feb 12, 2024
182 checks passed
@joshlf joshlf deleted the try-from-bytes-docs branch February 12, 2024 20:04
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