| 1 | // Copyright 2022 Unikie |
| 2 | // SPDX-License-Identifier: BSD-3-Clause OR Apache-2.0 |
| 3 | |
| 4 | #[cfg_attr(target_arch = "arm", path = "../bindings/arm/virtio_net.rs")] |
| 5 | #[cfg_attr(target_arch = "aarch64", path = "../bindings/aarch64/virtio_net.rs")] |
| 6 | #[cfg_attr(target_arch = "hexagon", path = "../bindings/hexagon/virtio_net.rs")] |
| 7 | #[cfg_attr( |
| 8 | target_arch = "loongarch64", |
| 9 | path = "../bindings/loongarch64/virtio_net.rs" |
| 10 | )] |
| 11 | #[cfg_attr(target_arch = "m68k", path = "../bindings/m68k/virtio_net.rs")] |
| 12 | #[cfg_attr(target_arch = "mips", path = "../bindings/mips/virtio_net.rs")] |
| 13 | #[cfg_attr(target_arch = "mips32r6", path = "../bindings/mips32r6/virtio_net.rs")] |
| 14 | #[cfg_attr(target_arch = "mips64", path = "../bindings/mips64/virtio_net.rs")] |
| 15 | #[cfg_attr(target_arch = "mips64r6", path = "../bindings/mips64r6/virtio_net.rs")] |
| 16 | #[cfg_attr( |
| 17 | target_arch = "powerpc64", |
| 18 | path = "../bindings/powerpc64/virtio_net.rs" |
| 19 | )] |
| 20 | #[cfg_attr(target_arch = "riscv32", path = "../bindings/riscv32/virtio_net.rs")] |
| 21 | #[cfg_attr(target_arch = "riscv64", path = "../bindings/riscv64/virtio_net.rs")] |
| 22 | #[cfg_attr(target_arch = "s390x", path = "../bindings/s390x/virtio_net.rs")] |
| 23 | #[cfg_attr(target_arch = "sparc", path = "../bindings/sparc/virtio_net.rs")] |
| 24 | #[cfg_attr(target_arch = "sparc64", path = "../bindings/sparc64/virtio_net.rs")] |
| 25 | #[cfg_attr(target_arch = "x86_64", path = "../bindings/x86_64/virtio_net.rs")] |
| 26 | #[cfg_attr(target_arch = "x86", path = "../bindings/x86/virtio_net.rs")] |
| 27 | mod generatedrust-analyzer cargo virtio-bindings 0.2.7 virtio_net/generated/; |
| 28 | pub use generatedrust-analyzer cargo virtio-bindings 0.2.7 virtio_net/generated/::*; |
| 29 | |
| 30 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::{Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#, Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#, Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result#}; |
| 31 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::{size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of()., transmuterust-analyzer cargo core https://github.com/rust-lang/rust/library/core intrinsics/transmute().}; |
| 32 | |
| 33 | impl Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for virtio_net_hdr_v1rust-analyzer cargo virtio-bindings 0.2.7 virtio_net/generated/virtio_net_hdr_v1# { |
| 34 | fn fmtrust-analyzer cargo virtio-bindings 0.2.7 virtio_net/impl#[virtio_net_hdr_v1][Debug]fmt().(&self, f: &mut Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 35 | // SAFETY: As of Linux v6.0, all union fields have compatible types. |
| 36 | // This means that it is safe to convert any variant into any other, |
| 37 | // as they all have the same size, alignment, and permitted values. |
| 38 | // https://doc.rust-lang.org/reference/items/unions.html#reading-and-writing-union-fields |
| 39 | let csum = unsafe { self.__bindgen_anon_1rust-analyzer cargo virtio-bindings 0.2.7 virtio_net/generated/virtio_net_hdr_v1#__bindgen_anon_1..csumrust-analyzer cargo virtio-bindings 0.2.7 virtio_net/generated/virtio_net_hdr_v1__bindgen_ty_1#csum. }; |
| 40 | |
| 41 | // We forgo determining the correct name of the fields in the |
| 42 | // union due to the complexity that would involve. |
| 43 | f.debug_structrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]debug_struct().("virtio_net_hdr_v1") |
| 44 | .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]field().("flags", &self.flagsrust-analyzer cargo virtio-bindings 0.2.7 virtio_net/generated/virtio_net_hdr_v1#flags.) |
| 45 | .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]field().("gso_type", &self.gso_typerust-analyzer cargo virtio-bindings 0.2.7 virtio_net/generated/virtio_net_hdr_v1#gso_type.) |
| 46 | .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]field().("hdr_len", &self.hdr_lenrust-analyzer cargo virtio-bindings 0.2.7 virtio_net/generated/virtio_net_hdr_v1#hdr_len.) |
| 47 | .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]field().("gso_size", &self.gso_sizerust-analyzer cargo virtio-bindings 0.2.7 virtio_net/generated/virtio_net_hdr_v1#gso_size.) |
| 48 | .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]field().("csum_start", &csum.startrust-analyzer cargo virtio-bindings 0.2.7 virtio_net/generated/virtio_net_hdr_v1__bindgen_ty_1__bindgen_ty_2#start.) |
| 49 | .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]field().("csum_offset", &csum.offsetrust-analyzer cargo virtio-bindings 0.2.7 virtio_net/generated/virtio_net_hdr_v1__bindgen_ty_1__bindgen_ty_2#offset.) |
| 50 | .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]field().("num_buffers", &self.num_buffersrust-analyzer cargo virtio-bindings 0.2.7 virtio_net/generated/virtio_net_hdr_v1#num_buffers.) |
| 51 | .finishrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]finish().() |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | impl PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#<Selfrust-analyzer cargo virtio-bindings 0.2.7 virtio_net/impl#[virtio_net_hdr_v1][`PartialEq<Self>`]> for virtio_net_hdr_v1rust-analyzer cargo virtio-bindings 0.2.7 virtio_net/generated/virtio_net_hdr_v1# { |
| 56 | fn eqrust-analyzer cargo virtio-bindings 0.2.7 virtio_net/impl#[virtio_net_hdr_v1][`PartialEq<Self>`]eq().<'a>(&'a self, other: &'a Selfrust-analyzer cargo virtio-bindings 0.2.7 virtio_net/impl#[virtio_net_hdr_v1][`PartialEq<Self>`]) -> bool { |
| 57 | // SAFETY: The values will be valid byte arrays, and the lifetimes match the |
| 58 | // original types. |
| 59 | unsafe { |
| 60 | let ptr1 = transmuterust-analyzer cargo core https://github.com/rust-lang/rust/library/core intrinsics/transmute().::<&'a Selfrust-analyzer cargo virtio-bindings 0.2.7 virtio_net/impl#[virtio_net_hdr_v1][`PartialEq<Self>`], &'a [u8; size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<Selfrust-analyzer cargo virtio-bindings 0.2.7 virtio_net/impl#[virtio_net_hdr_v1][`PartialEq<Self>`]>()]>(&self); |
| 61 | let ptr2 = transmuterust-analyzer cargo core https://github.com/rust-lang/rust/library/core intrinsics/transmute().::<&'a Selfrust-analyzer cargo virtio-bindings 0.2.7 virtio_net/impl#[virtio_net_hdr_v1][`PartialEq<Self>`], &'a [u8; size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<Selfrust-analyzer cargo virtio-bindings 0.2.7 virtio_net/impl#[virtio_net_hdr_v1][`PartialEq<Self>`]>()]>(&other); |
| 62 | ptr1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#eq().ptr2 |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 68 | fn virtio_net_hdr_v1_default_debugrust-analyzer cargo virtio-bindings 0.2.7 virtio_net/virtio_net_hdr_v1_default_debug().() { |
| 69 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{:?}", virtio_net_hdr_v1rust-analyzer cargo virtio-bindings 0.2.7 virtio_net/generated/virtio_net_hdr_v1#::defaultrust-analyzer cargo virtio-bindings 0.2.7 virtio_net/generated/impl#[virtio_net_hdr_v1][Default]default().()), "virtio_net_hdr_v1 { flags: 0, gso_type: 0, hdr_len: 0, gso_size: 0, csum_start: 0, csum_offset: 0, num_buffers: 0 }"); |
| 70 | } |
| 71 | |
| 72 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 73 | fn virtio_net_hdr_v1_hex_debugrust-analyzer cargo virtio-bindings 0.2.7 virtio_net/virtio_net_hdr_v1_hex_debug().() { |
| 74 | let expected = "virtio_net_hdr_v1 { |
| 75 | flags: 0x0, |
| 76 | gso_type: 0x0, |
| 77 | hdr_len: 0x0, |
| 78 | gso_size: 0x0, |
| 79 | csum_start: 0x0, |
| 80 | csum_offset: 0x0, |
| 81 | num_buffers: 0x0, |
| 82 | }"; |
| 83 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{:#x?}", virtio_net_hdr_v1rust-analyzer cargo virtio-bindings 0.2.7 virtio_net/generated/virtio_net_hdr_v1#::defaultrust-analyzer cargo virtio-bindings 0.2.7 virtio_net/generated/impl#[virtio_net_hdr_v1][Default]default().()), expected); |
| 84 | } |
| 85 | |
| 86 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 87 | fn virtio_net_hdr_v1_partial_eqrust-analyzer cargo virtio-bindings 0.2.7 virtio_net/virtio_net_hdr_v1_partial_eq().() { |
| 88 | let hdr1 = virtio_net_hdr_v1rust-analyzer cargo virtio-bindings 0.2.7 virtio_net/generated/virtio_net_hdr_v1#::defaultrust-analyzer cargo virtio-bindings 0.2.7 virtio_net/generated/impl#[virtio_net_hdr_v1][Default]default().(); |
| 89 | let hdr2 = virtio_net_hdr_v1rust-analyzer cargo virtio-bindings 0.2.7 virtio_net/generated/virtio_net_hdr_v1# { |
| 90 | flagsrust-analyzer cargo virtio-bindings 0.2.7 virtio_net/generated/virtio_net_hdr_v1#flags.: 1, |
| 91 | ..Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo virtio-bindings 0.2.7 virtio_net/generated/impl#[virtio_net_hdr_v1][Default]default().() |
| 92 | }; |
| 93 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(hdr1, hdr1); |
| 94 | assert_nerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_ne!!(hdr1, hdr2); |
| 95 | } |