Skip to content

Commit

Permalink
Make trait impls more consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
dralley committed Nov 14, 2023
1 parent dcb93be commit d3e61d8
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ md-5 = "0.10.5"
# bitflags = "1.3.2"
hex = "0.4.3"
indexmap = "2.0.0"
pyo3 = { version = "0.18.1", features = ["extension-module"], optional = true }
pyo3 = { version = "0.20.0", features = ["extension-module"], optional = true }

[lib]
name = "rpmrepo_metadata"
Expand Down
2 changes: 1 addition & 1 deletion src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use std::fmt;
/// without a caret, e.g. 0.5.0 vs 0.5.0~rc1. Including ^ in a version is used for denoting snapshots
/// not directly associated with an upstream release and will force it to sort higher, e.g.
/// 0.5.0 vs 0.5.0^deadbeef
#[derive(Debug, Eq, Default, Clone)]
#[derive(Clone, Debug, Default, Eq, Hash)]
pub struct EVR {
pub epoch: String,
pub version: String,
Expand Down
35 changes: 27 additions & 8 deletions src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use std::convert::TryInto;
use std::io::{BufRead, Write};
use std::hash::{Hash, Hasher};
use std::os::unix::prelude::MetadataExt;
use std::path::{Path, PathBuf};

Expand Down Expand Up @@ -155,7 +156,7 @@ impl TryInto<CompressionType> for &str {
// }
// }

#[derive(Debug, PartialEq, Default)]
#[derive(Clone, Default, Debug, PartialEq, Hash)]
pub struct Package {
// pub(crate) parse_state: ParseState,
pub name: String,
Expand Down Expand Up @@ -576,7 +577,7 @@ impl Package {
}
}

#[derive(Debug, PartialEq, Clone, Copy)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum ChecksumType {
Md5,
Sha1,
Expand All @@ -593,7 +594,7 @@ impl Default for ChecksumType {
}
}

#[derive(Debug, PartialEq, Clone)]
#[derive(Clone, Debug, PartialEq)]
pub enum Checksum {
Md5(String),
Sha1(String),
Expand All @@ -611,6 +612,23 @@ impl Default for Checksum {
}
}

impl Hash for Checksum {
fn hash<H: Hasher>(&self, state: &mut H) {
match self {
Self::Md5(hash) => format!("md5:{}", hash).hash(state),
Self::Sha1(hash) => format!("sha1:{}", hash).hash(state),
Self::Sha224(hash) => format!("sha224:{}", hash).hash(state),
Self::Sha256(hash) => format!("sha256:{}", hash).hash(state),
Self::Sha384(hash) => format!("sha384:{}", hash).hash(state),
Self::Sha512(hash) => format!("sha512:{}", hash).hash(state),
// TODO: adjust this representation. Currently these exist because of reuse of these enums
// to represent intermediate parsing states, but those probably ought to be pulled out somehow
Self::Unknown(hash) => unimplemented!(),
Self::Empty => unimplemented!(),
}
}
}

impl Checksum {
pub fn try_create<N: AsRef<[u8]> + Sized>(
checksum_type: N,
Expand Down Expand Up @@ -719,21 +737,21 @@ impl Checksum {
}
}

#[derive(Clone, Debug, PartialEq, Default)]
#[derive(Clone, Debug, Default, Hash, PartialEq)]
pub struct Changelog {
pub author: String,
pub timestamp: u64,
pub description: String,
}

#[derive(Debug, PartialEq, Default)]
#[derive(Copy, Clone, Debug, Default, Hash, PartialEq)]
pub struct HeaderRange {
pub start: u64,
pub end: u64,
}

// Requirement (Provides, Conflicts, Obsoletes, Requires).
#[derive(Clone, Debug, PartialEq, Default)]
#[derive(Clone, Debug, Default, Hash, PartialEq)]
pub struct Requirement {
pub name: String,
pub flags: Option<String>,
Expand All @@ -743,6 +761,7 @@ pub struct Requirement {
pub preinstall: bool,
}

#[derive(Copy, Clone, Debug, Hash, PartialEq)]
pub enum RequirementType {
LT,
GT,
Expand Down Expand Up @@ -780,7 +799,7 @@ impl TryFrom<&str> for RequirementType {
}
}

#[derive(Clone, Copy, Debug, PartialEq)]
#[derive(Copy, Clone, Debug, PartialEq, Hash)]
pub enum FileType {
File,
Dir,
Expand Down Expand Up @@ -814,7 +833,7 @@ impl Default for FileType {
}
}

#[derive(Clone, Debug, PartialEq, Default)]
#[derive(Clone, Debug, Default, Hash, PartialEq)]
pub struct PackageFile {
pub filetype: FileType,
pub path: String,
Expand Down
2 changes: 1 addition & 1 deletion src/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ impl Repository {
/// - `metadata_compression_type` - The type of compression to use for repository metadata.
/// - `metadata_checksum_type` - The type of checksums to use for metadata.
/// - `package_checksum_type` - The type of checksums to use for packages.
#[derive(Debug, Copy, Clone)]
#[derive(Copy, Clone, Debug)]
pub struct RepositoryOptions {
pub simple_metadata_filenames: bool,
pub metadata_compression_type: CompressionType,
Expand Down

0 comments on commit d3e61d8

Please sign in to comment.