Skip to content

Commit

Permalink
Merge pull request #35 from luser/tryintoctx-primitive-refs
Browse files Browse the repository at this point in the history
Implement IntoCtx/TryIntoCtx for references to primitive types.
  • Loading branch information
m4b authored Sep 14, 2018
2 parents 62d6ade + d718f22 commit afbd412
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 afbd412

Please sign in to comment.