borderless_hash/
hash_generated.rs1use core::mem;
7use core::cmp::Ordering;
8
9extern crate flatbuffers;
10use self::flatbuffers::{EndianScalar, Follow};
11
12#[repr(transparent)]
14#[derive(Clone, Copy, PartialEq)]
15pub struct Hash256(pub [u8; 32]);
16impl Default for Hash256 {
17 fn default() -> Self {
18 Self([0; 32])
19 }
20}
21impl core::fmt::Debug for Hash256 {
22 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
23 f.debug_struct("Hash256")
24 .field("bytes", &self.bytes())
25 .finish()
26 }
27}
28
29impl flatbuffers::SimpleToVerifyInSlice for Hash256 {}
30impl<'a> flatbuffers::Follow<'a> for Hash256 {
31 type Inner = &'a Hash256;
32 #[inline]
33 unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
34 <&'a Hash256>::follow(buf, loc)
35 }
36}
37impl<'a> flatbuffers::Follow<'a> for &'a Hash256 {
38 type Inner = &'a Hash256;
39 #[inline]
40 unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
41 flatbuffers::follow_cast_ref::<Hash256>(buf, loc)
42 }
43}
44impl<'b> flatbuffers::Push for Hash256 {
45 type Output = Hash256;
46 #[inline]
47 unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
48 let src = ::core::slice::from_raw_parts(self as *const Hash256 as *const u8, Self::size());
49 dst.copy_from_slice(src);
50 }
51}
52
53impl<'a> flatbuffers::Verifiable for Hash256 {
54 #[inline]
55 fn run_verifier(
56 v: &mut flatbuffers::Verifier, pos: usize
57 ) -> Result<(), flatbuffers::InvalidFlatbuffer> {
58 use self::flatbuffers::Verifiable;
59 v.in_buffer::<Self>(pos)
60 }
61}
62
63impl<'a> Hash256 {
64 #[allow(clippy::too_many_arguments)]
65 pub fn new(
66 bytes: &[u8; 32],
67 ) -> Self {
68 let mut s = Self([0; 32]);
69 s.set_bytes(bytes);
70 s
71 }
72
73 pub fn bytes(&'a self) -> flatbuffers::Array<'a, u8, 32> {
74 unsafe { flatbuffers::Array::follow(&self.0, 0) }
78 }
79
80 pub fn set_bytes(&mut self, items: &[u8; 32]) {
81 unsafe { flatbuffers::emplace_scalar_array(&mut self.0, 0, items) };
85 }
86
87}
88