| 1 |
// Copyright 2024 The Fuchsia Authors |
| 2 |
// |
| 3 |
// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 |
| 4 |
// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT |
| 5 |
// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. |
| 6 |
// This file may not be copied, modified, or distributed except according to |
| 7 |
// those terms. |
| 8 |
|
| 9 |
// See comment in `include.rs` for why we disable the prelude. |
| 10 |
#![no_implicit_prelude] |
| 11 |
#![allow(warnings)] |
| 12 |
|
| 13 |
include!("include.rs"); |
| 14 |
|
| 15 |
#[derive(imp::IntoBytes, imp::Immutable, imp::ByteHash)] |
| 16 |
#[repr(C)] |
| 17 |
struct Struct { |
| 18 |
a: u64, |
| 19 |
b: u32, |
| 20 |
c: u32, |
| 21 |
} |
| 22 |
|
| 23 |
util_assert_impl_all!(Struct: imp::IntoBytes, imp::hash::Hash); |
| 24 |
|
| 25 |
#[test] |
| 26 |
fn test_hash() { |
| 27 |
use imp::{ |
| 28 |
hash::{Hash, Hasher}, |
| 29 |
DefaultHasher, |
| 30 |
}; |
| 31 |
fn hash(val: impl Hash) -> u64 { |
| 32 |
let mut hasher = DefaultHasher::new(); |
| 33 |
val.hash(&mut hasher); |
| 34 |
hasher.finish() |
| 35 |
} |
| 36 |
hash(Struct { a: 10, b: 15, c: 20 }); |
| 37 |
hash(&[Struct { a: 10, b: 15, c: 20 }, Struct { a: 5, b: 4, c: 3 }]); |
| 38 |
} |