Skip to content

Commit

Permalink
Automatically derive Eq and Hash for Label (#676)
Browse files Browse the repository at this point in the history
Ref #630
  • Loading branch information
tiziano88 authored Mar 6, 2020
1 parent ea9ce44 commit ca6eb86
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 16 deletions.
5 changes: 4 additions & 1 deletion oak/server/rust/oak_abi/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@ fn main() {
// https://doc.rust-lang.org/cargo/reference/build-scripts.html#rerun-if-changed
println!("cargo:rerun-if-changed={}", oak_api_path.to_str().unwrap());

prost_build::compile_protos(&[oak_api_path, policy_path], &[proto_dir]).unwrap();
prost_build::Config::new()
.type_attribute(".oak.policy", "#[derive(Eq,Hash)]")
.compile_protos(&[oak_api_path, policy_path], &[proto_dir])
.unwrap();
}
15 changes: 0 additions & 15 deletions oak/server/rust/oak_abi/src/label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,6 @@ pub trait Label: Sized {
fn can_flow_to(&self, other: &Self) -> bool;
}

// Implement the necessary traits on `Tag` so that it may be used in `HashSet`.

impl Eq for crate::proto::policy::Tag {}

#[allow(clippy::derive_hash_xor_eq)]
impl std::hash::Hash for crate::proto::policy::Tag {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
// As a quick solution, we simply serialize the message and hash the resulting `Vec`.
let mut bytes = Vec::new();
self.encode(&mut bytes)
.expect("could not serialize to bytes");
bytes.hash(state);
}
}

impl Label for crate::proto::policy::Label {
fn serialize(&self) -> Vec<u8> {
let mut bytes = Vec::new();
Expand Down

0 comments on commit ca6eb86

Please sign in to comment.