Skip to content

Commit

Permalink
Implement IntoCtx/TryIntoCtx for references to primitive types.
Browse files Browse the repository at this point in the history
This should help in fixing m4b/scroll_derive#15 .
  • Loading branch information
luser committed Sep 13, 2018
1 parent 62d6ade commit d718f22
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ macro_rules! into_ctx_impl {
write_into!($typ, $size, self, dst, le);
}
}
impl<'a> IntoCtx<Endian> for &'a $typ {
#[inline]
fn into_ctx(self, dst: &mut [u8], le: Endian) {
(*self).into_ctx(dst, le)
}
}
impl TryIntoCtx<Endian> for $typ where $typ: IntoCtx<Endian> {
type Error = error::Error;
type Size = usize;
Expand All @@ -201,6 +207,14 @@ macro_rules! into_ctx_impl {
}
}
}
impl<'a> TryIntoCtx<Endian> for &'a $typ {
type Error = error::Error;
type Size = usize;
#[inline]
fn try_into_ctx(self, dst: &mut [u8], le: Endian) -> error::Result<Self::Size> {
(*self).try_into_ctx(dst, le)
}
}
}
}

Expand Down Expand Up @@ -295,7 +309,6 @@ macro_rules! from_ctx_float_impl {
}
}
}

impl<'a> TryFromCtx<'a, Endian> for $typ where $typ: FromCtx<Endian> {
type Error = error::Error;
type Size = usize;
Expand Down Expand Up @@ -334,6 +347,12 @@ macro_rules! into_ctx_float_impl {
write_into!(signed_to_unsigned!($typ), $size, transmute::<$typ, signed_to_unsigned!($typ)>(self), dst, le);
}
}
impl<'a> IntoCtx<Endian> for &'a $typ {
#[inline]
fn into_ctx(self, dst: &mut [u8], le: Endian) {
(*self).into_ctx(dst, le)
}
}
impl TryIntoCtx<Endian> for $typ where $typ: IntoCtx<Endian> {
type Error = error::Error;
type Size = usize;
Expand All @@ -347,6 +366,14 @@ macro_rules! into_ctx_float_impl {
}
}
}
impl<'a> TryIntoCtx<Endian> for &'a $typ {
type Error = error::Error;
type Size = usize;
#[inline]
fn try_into_ctx(self, dst: &mut [u8], le: Endian) -> error::Result<Self::Size> {
(*self).try_into_ctx(dst, le)
}
}
}
}

Expand Down

0 comments on commit d718f22

Please sign in to comment.