aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSam Whited <sam@samwhited.com>2017-03-28 11:57:12 -0500
committerAndrew Gallant <jamslam@gmail.com>2017-03-28 13:40:45 -0400
commit3ec105c08d1ba443f802b251f239161e771de94a (patch)
tree6fbc63802beab4833b229e089d3146369b2d36bf /src
parente7cb5abf22b7acc99bc7becc1572615f6cb6662f (diff)
downloadbyteorder-3ec105c08d1ba443f802b251f239161e771de94a.tar.gz
Seal ByteOrder trait against external implementations
Fixes #69 Updates #76
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 035aca6..3616e01 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -87,6 +87,13 @@ fn pack_size(n: u64) -> usize {
}
}
+mod private {
+ /// Sealed stops crates other than byteorder from implementing any traits that use it.
+ pub trait Sealed{}
+ impl Sealed for super::LittleEndian {}
+ impl Sealed for super::BigEndian {}
+}
+
/// ByteOrder describes types that can serialize integers as bytes.
///
/// Note that `Self` does not appear anywhere in this trait's definition!
@@ -95,6 +102,8 @@ fn pack_size(n: u64) -> usize {
///
/// This crate provides two types that implement `ByteOrder`: `BigEndian`
/// and `LittleEndian`.
+/// This trait is sealed and cannot be implemented for callers to avoid
+/// breaking backwards compatibility when adding new derived traits.
///
/// # Examples
///
@@ -118,7 +127,7 @@ fn pack_size(n: u64) -> usize {
/// assert_eq!(-50_000, BigEndian::read_i16(&buf));
/// ```
pub trait ByteOrder
- : Clone + Copy + Debug + Default + Eq + Hash + Ord + PartialEq + PartialOrd {
+ : Clone + Copy + Debug + Default + Eq + Hash + Ord + PartialEq + PartialOrd + private::Sealed {
/// Reads an unsigned 16 bit integer from `buf`.
///
/// # Panics