Convert Metadata::role into associated constant
diff --git a/src/metadata.rs b/src/metadata.rs
index c9f2bfb..777cb16 100644
--- a/src/metadata.rs
+++ b/src/metadata.rs
@@ -215,7 +215,7 @@
/// Top level trait used for role metadata.
pub trait Metadata: Debug + PartialEq + Serialize + DeserializeOwned {
/// The role associated with the metadata.
- fn role() -> Role;
+ const ROLE: Role;
}
/// A piece of raw metadata with attached signatures.
@@ -578,9 +578,7 @@
}
impl Metadata for RootMetadata {
- fn role() -> Role {
- Role::Root
- }
+ const ROLE: Role = Role::Root;
}
impl Serialize for RootMetadata {
@@ -809,9 +807,7 @@
}
impl Metadata for TimestampMetadata {
- fn role() -> Role {
- Role::Timestamp
- }
+ const ROLE: Role = Role::Timestamp;
}
impl Serialize for TimestampMetadata {
@@ -967,9 +963,7 @@
}
impl Metadata for SnapshotMetadata {
- fn role() -> Role {
- Role::Snapshot
- }
+ const ROLE: Role = Role::Snapshot;
}
impl Serialize for SnapshotMetadata {
@@ -1272,9 +1266,7 @@
}
impl Metadata for TargetsMetadata {
- fn role() -> Role {
- Role::Targets
- }
+ const ROLE: Role = Role::Targets;
}
impl Serialize for TargetsMetadata {
diff --git a/src/repository.rs b/src/repository.rs
index 313069f..9ee082d 100644
--- a/src/repository.rs
+++ b/src/repository.rs
@@ -74,9 +74,9 @@
where
M: Metadata,
{
- if !M::role().fuzzy_matches_path(meta_path) {
+ if !M::ROLE.fuzzy_matches_path(meta_path) {
return Err(Error::IllegalArgument(
- format!("Role {} does not match path {:?}", M::role(), meta_path),
+ format!("Role {} does not match path {:?}", M::ROLE, meta_path),
));
}