You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Timely communication has a Serialize trait, with methods
pubtraitSerialize{/// Append the binary representation of `self` to a vector of bytes. The `&mut self` argument/// may be mutated, but the second argument should only be appended to.fninto_bytes(&mutself,&mutVec<u8>);/// Recover an instance of Self from its binary representation. The `&mut Vec<u8>` argument may/// be taken with `mem::replace` if it is needed.fnfrom_bytes(&mutVec<u8>) -> Self;}
The first method seems fine for now, but from_bytes has the issue that it is unable to re-use existing Self allocations, as there is nowhere to grab one from (short of a stashed Rc<RefCell<_>> cache).
Timely's Message type gets around this by using Vec<u8> as its backing storage, which is great except that no one else can rely on this, and so returned Message objects just get dropped on the floor, as we don't know how to destructure them into useful parts.
I think we could take inspiration from Rust's Clone trait, which has a method
fnclone_from(&mutself,source:&Self){ ...}
We could totally change the signature of from_bytes to be
fnfrom_bytes(&mutself,&mutVec<u8>);
with the intent that one should feel free to re-use as much of &mut self as you can afford, as long as what results is still valid. If you happen to swap around the &mut Vec<u8> in the process, good for you.
This seems strictly better than requiring a freshly constructed Self, as simply clobbering the &mut self input argument is always an option.
The text was updated successfully, but these errors were encountered:
Timely communication has changed substantially, and should no longer have this problem. With #135, RefOrMuts swap method deserializes into an existing allocated object, which addresses this problem.
Timely communication has a
Serialize
trait, with methodsThe first method seems fine for now, but
from_bytes
has the issue that it is unable to re-use existingSelf
allocations, as there is nowhere to grab one from (short of a stashedRc<RefCell<_>>
cache).Timely's
Message
type gets around this by usingVec<u8>
as its backing storage, which is great except that no one else can rely on this, and so returnedMessage
objects just get dropped on the floor, as we don't know how to destructure them into useful parts.I think we could take inspiration from Rust's
Clone
trait, which has a methodWe could totally change the signature of
from_bytes
to bewith the intent that one should feel free to re-use as much of
&mut self
as you can afford, as long as what results is still valid. If you happen to swap around the&mut Vec<u8>
in the process, good for you.This seems strictly better than requiring a freshly constructed
Self
, as simply clobbering the&mut self
input argument is always an option.The text was updated successfully, but these errors were encountered: