From eba9dd21c7ca1c444e087a1eccf7c848b80b5ed6 Mon Sep 17 00:00:00 2001 From: Joshua Liebow-Feeser Date: Mon, 12 Feb 2024 11:57:28 -0800 Subject: [PATCH] [doc] TryFromBytes, IntoBytes aren't symmetrical (#860) Makes progress on #5 --- src/lib.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 7db2fc7a97..0860be9c4e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1186,6 +1186,16 @@ pub unsafe trait NoCell { /// If you are negatively affected by lack of support for a particular type, /// we encourage you to let us know by [filing an issue][github-repo]. /// +/// # `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`. +/// /// # Safety /// /// On its own, `T: TryFromBytes` does not make any guarantees about the layout