zlib-compressed data compiles
[pspp] / rust / src / endian.rs
index 51952137b7b657d123d9394413388f6340f65642..6bd25ab95ac0408793983a34ed18ca8ad68f0db6 100644 (file)
@@ -34,6 +34,18 @@ impl Endian {
     }
 }
 
+pub trait ToBytes<T, const N: usize> {
+    fn to_bytes(self, value: T) -> [u8; N];
+}
+impl ToBytes<f64, 8> for Endian {
+    fn to_bytes(self, value: f64) -> [u8; 8] {
+        match self {
+            Endian::Big => f64::to_be_bytes(value),
+            Endian::Little => f64::to_le_bytes(value),
+        }
+    }
+}
+
 /// Parses an `N`-byte slice in one of the supported formats into native format
 /// as type `T`.
 pub trait Parse<T, const N: usize> {