Add generic serialization implementations for Boxs and 3-tuples
[rust-lightning] / lightning / src / util / ser.rs
index a49b033db3d51010073260f8d0023dac5e6a5c1c..4e69a37d20e9fcc5e0d093804136ef9f90be1747 100644 (file)
@@ -698,6 +698,18 @@ impl Readable for PaymentSecret {
        }
 }
 
+impl<T: Writeable> Writeable for Box<T> {
+       fn write<W: Writer>(&self, w: &mut W) -> Result<(), ::std::io::Error> {
+               T::write(&**self, w)
+       }
+}
+
+impl<T: Readable> Readable for Box<T> {
+       fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
+               Ok(Box::new(Readable::read(r)?))
+       }
+}
+
 impl<T: Writeable> Writeable for Option<T> {
        fn write<W: Writer>(&self, w: &mut W) -> Result<(), ::std::io::Error> {
                match *self {
@@ -824,3 +836,19 @@ impl<A: Writeable, B: Writeable> Writeable for (A, B) {
                self.1.write(w)
        }
 }
+
+impl<A: Readable, B: Readable, C: Readable> Readable for (A, B, C) {
+       fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
+               let a: A = Readable::read(r)?;
+               let b: B = Readable::read(r)?;
+               let c: C = Readable::read(r)?;
+               Ok((a, b, c))
+       }
+}
+impl<A: Writeable, B: Writeable, C: Writeable> Writeable for (A, B, C) {
+       fn write<W: Writer>(&self, w: &mut W) -> Result<(), ::std::io::Error> {
+               self.0.write(w)?;
+               self.1.write(w)?;
+               self.2.write(w)
+       }
+}