From 39e80cca433ad127bfa58cebbbaa4f4791246963 Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Sun, 18 Mar 2018 15:49:59 +0900 Subject: [PATCH] Prevent downstream implementations of the Integer trait --- src/lib.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index a7e5a36..08c452c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,7 +22,12 @@ pub fn write(wr: W, value: V) -> io::Result { 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(self, W) -> io::Result; } @@ -51,6 +56,8 @@ macro_rules! impl_IntegerCommon { Ok(bytes.len()) } } + + impl private::Sealed for $t {} }; }