Prevent downstream implementations of the Integer trait

This commit is contained in:
Mike Hommey 2018-03-18 15:49:59 +09:00
parent ccdcae586f
commit 39e80cca43
1 changed files with 8 additions and 1 deletions

View File

@ -22,7 +22,12 @@ pub fn write<W: io::Write, V: Integer>(wr: W, value: V) -> io::Result<usize> {
value.write(wr)
}
pub trait Integer {
// Seal to prevent downstream implementations of the Integer trait.
mod private {
pub trait Sealed {}
}
pub trait Integer: private::Sealed {
fn write<W: io::Write>(self, W) -> io::Result<usize>;
}
@ -51,6 +56,8 @@ macro_rules! impl_IntegerCommon {
Ok(bytes.len())
}
}
impl private::Sealed for $t {}
};
}