]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/hir/svh.rs
Auto merge of #35856 - phimuemue:master, r=brson
[rust.git] / src / librustc / hir / svh.rs
index d4e797c9f2d25b758cea756355739c4be43158ee..ae1f9d3028c2c08075934fc18654d212bb7decaa 100644 (file)
@@ -17,6 +17,7 @@
 
 use std::fmt;
 use std::hash::{Hash, Hasher};
+use serialize::{Encodable, Decodable, Encoder, Decoder};
 
 #[derive(Copy, Clone, PartialEq, Eq, Debug)]
 pub struct Svh {
@@ -51,3 +52,17 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         f.pad(&self.to_string())
     }
 }
+
+impl Encodable for Svh {
+    fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
+        s.emit_u64(self.as_u64().to_le())
+    }
+}
+
+impl Decodable for Svh {
+    fn decode<D: Decoder>(d: &mut D) -> Result<Svh, D::Error> {
+        d.read_u64()
+         .map(u64::from_le)
+         .map(Svh::new)
+    }
+}