summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Moroney <darakian@gmail.com>2020-08-02 14:56:34 -0700
committerGitHub <noreply@github.com>2020-08-02 14:56:34 -0700
commit7035276acddb21e9b13bc4350fd8d35c0e26ddc6 (patch)
tree5318dce1a1494bd44d2b2110fdda1f3c50f3ae2f
parent3636ebf4247fe4625a306715e96c51d26327acdf (diff)
parentc147bac7b5d3529c5fe8050d285d98b899873c46 (diff)
Merge pull request #33 from darakian/impl-serialize-for-FileInfo
Remove serde-derive
-rw-r--r--Cargo.toml1
-rw-r--r--src/lib.rs18
2 files changed, 16 insertions, 3 deletions
diff --git a/Cargo.toml b/Cargo.toml
index d8415c0..cd0de6f 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -15,7 +15,6 @@ clap = "2.33.0"
rayon = "1.3"
serde = "1.0"
serde_json = "1.0"
-serde_derive = "1.0"
siphasher = "0.3"
nohash-hasher = "0.1.1"
diff --git a/src/lib.rs b/src/lib.rs
index 0151143..567b0c1 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -9,7 +9,7 @@ use std::fs::{self, DirEntry};
use std::io::{Read};
use std::path::{PathBuf, Path};
use std::cmp::Ordering;
-use serde_derive::{Serialize};
+use serde::ser::{Serialize, Serializer, SerializeStruct};
use siphasher::sip128::Hasher128;
use rayon::prelude::*;
use std::sync::mpsc::{Sender, channel};
@@ -31,7 +31,7 @@ enum ChannelPackage{
}
/// Serializable struct containing entries for a specific file. These structs will identify individual files as a collection of paths and associated hash and length data.
-#[derive(Debug, Serialize)]
+#[derive(Debug)]
pub struct Fileinfo{
full_hash: Option<u128>,
partial_hash: Option<u128>,
@@ -179,6 +179,20 @@ impl Fileinfo{
}
}
+impl Serialize for Fileinfo{
+ fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
+ where
+ S: Serializer,
+ {
+ let mut state = serializer.serialize_struct("Fileinfo", 4)?;
+ state.serialize_field("partial_hash", &self.partial_hash)?;
+ state.serialize_field("full_hash", &self.full_hash)?;
+ state.serialize_field("file_length", &self.file_length)?;
+ state.serialize_field("file_paths", &self.file_paths)?;
+ state.end()
+ }
+}
+
impl PartialEq for Fileinfo{
fn eq(&self, other: &Fileinfo) -> bool {
(self.file_length==other.file_length)&&