-
Notifications
You must be signed in to change notification settings - Fork 14
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
[WIP] [Help wanted] Adapt to upcoming changes in Abomonation #11
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,38 +14,51 @@ fn derive_abomonation(mut s: synstructure::Structure) -> proc_macro2::TokenStrea | |
}); | ||
|
||
let entomb = s.each(|bi| quote! { | ||
::abomonation::Abomonation::entomb(#bi, _write)?; | ||
::abomonation::Entomb::entomb(#bi, _write)?; | ||
}); | ||
|
||
let extent = s.each(|bi| quote! { | ||
sum += ::abomonation::Abomonation::extent(#bi); | ||
sum += ::abomonation::Entomb::extent(#bi); | ||
}); | ||
|
||
s.bind_with(|_| synstructure::BindStyle::RefMut); | ||
|
||
let exhume = s.each(|bi| quote! { | ||
let temp = bytes; | ||
bytes = ::abomonation::Abomonation::exhume(#bi, temp)?; | ||
bytes = ::abomonation::Exhume::exhume(From::from(#bi), bytes)?; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Abomonation API change from TimelyDataflow/abomonation#22: |
||
}); | ||
|
||
s.bound_impl(quote!(abomonation::Abomonation), quote! { | ||
#[inline] unsafe fn entomb<W: ::std::io::Write>(&self, _write: &mut W) -> ::std::io::Result<()> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I removed the inline directives since I established in TimelyDataflow/abomonation#24 that they are actually very rarely needed. It's probably better to let the compiler's optimizer do its job if it does it reasonably well. |
||
match *self { #entomb } | ||
Ok(()) | ||
} | ||
#[allow(unused_mut)] | ||
#[inline] fn extent(&self) -> usize { | ||
let mut sum = 0; | ||
match *self { #extent } | ||
sum | ||
s.gen_impl(quote! { | ||
extern crate abomonation; | ||
extern crate std; | ||
|
||
gen unsafe impl abomonation::Entomb for @Self { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Abomonation API change from TimelyDataflow/abomonation#25: implementing |
||
unsafe fn entomb<W: ::std::io::Write>(&self, _write: &mut W) -> ::std::io::Result<()> { | ||
match *self { #entomb } | ||
Ok(()) | ||
} | ||
|
||
#[allow(unused_mut)] | ||
fn extent(&self) -> usize { | ||
let mut sum = 0; | ||
match *self { #extent } | ||
sum | ||
} | ||
} | ||
#[allow(unused_mut)] | ||
#[inline] unsafe fn exhume<'a,'b>( | ||
&'a mut self, | ||
mut bytes: &'b mut [u8] | ||
) -> Option<&'b mut [u8]> { | ||
match *self { #exhume } | ||
Some(bytes) | ||
|
||
gen unsafe impl<'de> abomonation::Exhume<'de> for @Self | ||
where Self: 'de, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This A Since |
||
{ | ||
#[allow(unused_mut)] | ||
unsafe fn exhume( | ||
self_: std::ptr::NonNull<Self>, | ||
mut bytes: &'de mut [u8] | ||
) -> Option<&'de mut [u8]> { | ||
// FIXME: This (briefly) constructs an &mut _ to invalid data | ||
// (via "ref mut"), which is UB. The proposed &raw mut | ||
// operator would allow avoiding this. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As the FIXME says, this operation cannot be implemented without UB in Rust, for now, but there is a new language feature on the way that should fix that. |
||
match *self_.as_ptr() { #exhume } | ||
Some(bytes) | ||
} | ||
} | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Abomonation API change from TimelyDataflow/abomonation#28: The
Abomonation
trait is now API sugar for two separate traits,Entomb
andExhume
, via a blanket impl which ensures that everything which implements those two traits implementsAbomonation
. This was done to allow deserialization of types which contain references, which requires adding a lifetime parameter to the deserialization trait (as in serde).The semantics of
Exhume<'de>
's lifetime parameter is that ifT: Exhume<'de>
, it means that it is okay to deserialize an&'de T
from&'de mut [u8]
bytes. This is not always the case for references, for example you don't want to allow people to deserialize&'static Something
from stack-allocated bytes.