Debian Codegraph @

debian/rust-vendor/zerocopy-derive/tests/hash.rs

raw
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 #[zerocopy(crate = "zerocopy_renamed")]
17 #[repr(C)]
18 struct Struct {
19 a: u64,
20 b: u32,
21 c: u32,
22 }
23
24 util_assert_impl_all!(Struct: imp::IntoBytes, imp::hash::Hash);
25
26 #[test]
27 fn test_hash() {
28 use imp::{
29 hash::{Hash, Hasher},
30 DefaultHasher,
31 };
32 fn hash(val: impl Hash) -> u64 {
33 let mut hasher = DefaultHasher::new();
34 val.hash(&mut hasher);
35 hasher.finish()
36 }
37 hash(Struct { a: 10, b: 15, c: 20 });
38 hash(&[Struct { a: 10, b: 15, c: 20 }, Struct { a: 5, b: 4, c: 3 }]);
39 }