aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNick Fitzgerald <fitzgen@gmail.com>2016-11-05 16:57:31 -0700
committerAndrew Gallant <jamslam@gmail.com>2016-12-30 13:04:47 -0500
commitd9b95376d7ce79c9c763f14109612a3b070bf924 (patch)
treed08318a83df0882059cae479f446d012ee393e4a /src
parenta2efdd939f1d05379cb412e0b8670abcf5d6b9c6 (diff)
downloadbyteorder-d9b95376d7ce79c9c763f14109612a3b070bf924.tar.gz
Require impls for all derive-able traits for ByteOrder
This adds trait bounds to ByteOrder for all the traits that can automatically be derived. Next, it derives them all for BigEndian and LittleEndian. The exception is Default, which cannot be derived for enums, and it is explicitly implemented as unreachable. Fixes #52.
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 8038f75..f27dcc7 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -42,6 +42,8 @@ assert_eq!(wtr, vec![5, 2, 0, 3]);
#[cfg(feature = "std")]
extern crate core;
+use core::fmt::Debug;
+use core::hash::Hash;
use core::mem::transmute;
use core::ptr::copy_nonoverlapping;
@@ -114,7 +116,8 @@ fn pack_size(n: u64) -> usize {
/// BigEndian::write_i16(&mut buf, -50_000);
/// assert_eq!(-50_000, BigEndian::read_i16(&buf));
/// ```
-pub trait ByteOrder {
+pub trait ByteOrder
+ : Clone + Copy + Debug + Default + Eq + Hash + Ord + PartialEq + PartialOrd {
/// Reads an unsigned 16 bit integer from `buf`.
///
/// Panics when `buf.len() < 2`.
@@ -260,13 +263,27 @@ pub trait ByteOrder {
///
/// Note that this type has no value constructor. It is used purely at the
/// type level.
-#[allow(missing_copy_implementations)] pub enum BigEndian {}
+#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
+pub enum BigEndian {}
+
+impl Default for BigEndian {
+ fn default() -> BigEndian {
+ unreachable!()
+ }
+}
/// Defines little-endian serialization.
///
/// Note that this type has no value constructor. It is used purely at the
/// type level.
-#[allow(missing_copy_implementations)] pub enum LittleEndian {}
+#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
+pub enum LittleEndian {}
+
+impl Default for LittleEndian {
+ fn default() -> LittleEndian {
+ unreachable!()
+ }
+}
/// Defines network byte order serialization.
///