-
Notifications
You must be signed in to change notification settings - Fork 30
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
Is it okay to implement Abomonation for both T and &T? #27
Comments
(As an aside, because Rust references are marked |
I'm a bit scrambled at the moment, but want to pop in with a quick comment. It is generally unsafe to implement Serde has the same problem, and the result seems to be to have I'm sorry for not popping in earlier with this. Very behind your rate of production. Serde has the same problem, and the answer |
I have an |
Yup, I could use a look at that! (Technically, I only need |
On the road atm, but will get it soon! |
EDIT: Fixed after cross-checking how serde does it. Just to see if I understand, the idea would be to...
As a nice side effect, this should also resolve a problem which I had when trying to express the lifetimes of my |
This is basically correct yes! I appear to have deleted the file, unfortunately, but you have the spirit of it. I can reconstruct it this weekend (it was very minor, just around the impl<'bytes> Abomonation<'bytes> for &'bytes ConcreteT and skip the other lifetime (allow Rust to coerce the lifetime as it sees appropriate). |
Serde's author seems unconvinced:
OTOH, since the Abomonation impl is generic, it's probably okay to kill the lifetime on |
From the point of view of abomonation's core semantics, there is nothing wrong with providing implementations of the
Abomonation
trait for both a typeT
and a reference to it&T
. Basically, the implementation for&T
works exactly like that ofBox<T>
in abomonation's current master branch.Such implementations would be useful for high-level users of
Abomonation
, who stick with derives,encode
,decode
andmeasure
, because they would allow safely auto-derivingAbomonation
for more types. Something which, as a matter of fact, I ended up wanting for my project.However, and that's the reason why I'm opening this issue before submitting my changes as a PR, there is also a significant ergonomic cost to doing so for any low-level user of
Abomonation
who calls into the trait directly.If
Abomonation
is implemented for bothT
and&T
, then anyone who uses theAbomonation
trait directly instead of going throughencode
,decode
andmeasure
must be super-careful, because method call syntax of thex.extent()
kind becomes a deadly trap that can very easily trigger the wrongAbomonation
impl through auto-Deref
magic.Instead, one must get into the habit of only calling
Abomonation
trait method viaU::extent(&x)
syntax, or if type U is unknown go for the somewhat less safe compromise ofAbomonation::extent(&x)
.Is this a trade-off that we can tolerate for the sake of having more
Abomonation
impls?The text was updated successfully, but these errors were encountered: