use serde::ser::{SerializeSeq, Serializer};
use serde::Serialize;
use std::collections::HashSet;
use std::ffi::OsString;
#[derive(Debug, Clone, Serialize)]
pub struct DuplicateObject {
#[serde(serialize_with = "osstring_serialize")]
pub duplicates: HashSet<OsString>,
#[serde(rename = "elementSize")]
pub size: u64,
}
fn osstring_serialize<S>(hs: &HashSet<OsString>, s: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let mut seq = s.serialize_seq(Some(hs.len()))?;
for item in hs.iter() {
let stringy: String = item
.to_owned()
.into_string()
.unwrap_or_else(|osstr| format!("Error decoding this: {:?}", osstr));
seq.serialize_element(&stringy)?;
}
seq.end()
}
impl DuplicateObject {
pub fn new(size: u64, duplicates: HashSet<OsString>) -> Self {
DuplicateObject { duplicates, size }
}
}
impl PartialEq for DuplicateObject {
fn eq(&self, other: &Self) -> bool {
self.duplicates == other.duplicates
}
}
impl Eq for DuplicateObject {}
#[derive(Debug, Eq, PartialEq)]
pub struct DuDeError {
error: String,
}