Skip to content

Commit

Permalink
Make Range<T> abomonable
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre Bogus committed Aug 15, 2020
1 parent 9294cd2 commit a75d453
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,22 @@ impl Abomonation for ::std::time::Duration { }

impl<T> Abomonation for PhantomData<T> {}

impl<T: Abomonation> Abomonation for std::ops::Range<T> {
#[inline(always)] unsafe fn entomb<W: Write>(&self, write: &mut W) -> IOResult<()> {
self.start.entomb(write)?;
self.end.entomb(write)?;
Ok(())
}
#[inline(always)] unsafe fn exhume<'a, 'b>(&'a mut self, mut bytes: &'b mut[u8]) -> Option<&'b mut [u8]> {
let tmp = bytes; bytes = self.start.exhume(tmp)?;
let tmp = bytes; bytes = self.end.exhume(tmp)?;
Some(bytes)
}
#[inline] fn extent(&self) -> usize {
self.start.extent() << 1
}
}

impl<T: Abomonation> Abomonation for Option<T> {
#[inline(always)] unsafe fn entomb<W: Write>(&self, write: &mut W) -> IOResult<()> {
if let &Some(ref inner) = self {
Expand Down Expand Up @@ -534,4 +550,4 @@ mod network {
impl Abomonation for SocketAddr { }
impl Abomonation for SocketAddrV4 { }
impl Abomonation for SocketAddrV6 { }
}
}

0 comments on commit a75d453

Please sign in to comment.