| 1 | |
| 2 | |
| 3 | #![allow(dead_code)] |
| 4 | |
| 5 | use ::*; |
| 6 | use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/; |
| 7 | |
| 8 | #[repr(C)] |
| 9 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 10 | struct Dummy1rust-analyzer cargo plain 0.2.3 tests/Dummy1# { |
| 11 | field1rust-analyzer cargo plain 0.2.3 tests/Dummy1#field1.: u64, |
| 12 | field2rust-analyzer cargo plain 0.2.3 tests/Dummy1#field2.: u32, |
| 13 | field3rust-analyzer cargo plain 0.2.3 tests/Dummy1#field3.: u16, |
| 14 | field4rust-analyzer cargo plain 0.2.3 tests/Dummy1#field4.: u8, |
| 15 | field5rust-analyzer cargo plain 0.2.3 tests/Dummy1#field5.: u8, |
| 16 | } |
| 17 | |
| 18 | unsafe impl Plain for Dummy1rust-analyzer cargo plain 0.2.3 tests/Dummy1# {} |
| 19 | |
| 20 | #[repr(C)] |
| 21 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 22 | struct Dummy2rust-analyzer cargo plain 0.2.3 tests/Dummy2# { |
| 23 | field1rust-analyzer cargo plain 0.2.3 tests/Dummy2#field1.: u8, |
| 24 | field2rust-analyzer cargo plain 0.2.3 tests/Dummy2#field2.: u8, |
| 25 | field3rust-analyzer cargo plain 0.2.3 tests/Dummy2#field3.: u16, |
| 26 | field4rust-analyzer cargo plain 0.2.3 tests/Dummy2#field4.: u32, |
| 27 | field5rust-analyzer cargo plain 0.2.3 tests/Dummy2#field5.: u64, |
| 28 | } |
| 29 | |
| 30 | unsafe impl Plain for Dummy2rust-analyzer cargo plain 0.2.3 tests/Dummy2# {} |
| 31 | |
| 32 | fn as_bytesrust-analyzer cargo plain 0.2.3 tests/as_bytes().<T: ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>(r: &T) -> &[u8] { |
| 33 | unsafe { methods::as_bytes(r) } |
| 34 | } |
| 35 | |
| 36 | fn as_mut_bytesrust-analyzer cargo plain 0.2.3 tests/as_mut_bytes().<T: Plain + ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#>(r: &mut T) -> &mut [u8] { |
| 37 | unsafe { methods::as_mut_bytes(r) } |
| 38 | } |
| 39 | |
| 40 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 41 | fn one_too_shortrust-analyzer cargo plain 0.2.3 tests/one_too_short().() { |
| 42 | let b = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0u8; 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().::<Dummy1rust-analyzer cargo plain 0.2.3 tests/Dummy1#>() -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). 1]; |
| 43 | |
| 44 | let r = Dummy1rust-analyzer cargo plain 0.2.3 tests/Dummy1#::from_bytes(&b); |
| 45 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(r == Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Error::TooShort)); |
| 46 | } |
| 47 | |
| 48 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 49 | fn unalignedrust-analyzer cargo plain 0.2.3 tests/unaligned().() { |
| 50 | let b = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0u8; 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().::<Dummy1rust-analyzer cargo plain 0.2.3 tests/Dummy1#>() +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). 1]; |
| 51 | let b = &b[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().; |
| 52 | |
| 53 | let r = Dummy1rust-analyzer cargo plain 0.2.3 tests/Dummy1#::from_bytes(&b); |
| 54 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(r == Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Error::BadAlignment)); |
| 55 | } |
| 56 | |
| 57 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 58 | fn copy_testrust-analyzer cargo plain 0.2.3 tests/copy_test().() { |
| 59 | let t1 = Dummy1rust-analyzer cargo plain 0.2.3 tests/Dummy1# { |
| 60 | field1rust-analyzer cargo plain 0.2.3 tests/Dummy1#field1.: 0xaaaaaaaaaaaaaaaau64, |
| 61 | field2rust-analyzer cargo plain 0.2.3 tests/Dummy1#field2.: 0xbbbbbbbbu32, |
| 62 | field3rust-analyzer cargo plain 0.2.3 tests/Dummy1#field3.: 0xccccu16, |
| 63 | field4rust-analyzer cargo plain 0.2.3 tests/Dummy1#field4.: 0xddu8, |
| 64 | field5rust-analyzer cargo plain 0.2.3 tests/Dummy1#field5.: 0xeeu8, |
| 65 | }; |
| 66 | |
| 67 | let mut t2 = Dummy2rust-analyzer cargo plain 0.2.3 tests/Dummy2#::defaultrust-analyzer cargo plain 0.2.3 tests/impl#[Dummy2][Default]default().(); |
| 68 | |
| 69 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(t2.copy_from_bytes(as_bytesrust-analyzer cargo plain 0.2.3 tests/as_bytes().(&t1)) == Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())); |
| 70 | |
| 71 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(t2.field1rust-analyzer cargo plain 0.2.3 tests/Dummy2#field1. == 0xaau8); |
| 72 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(t2.field2rust-analyzer cargo plain 0.2.3 tests/Dummy2#field2. == 0xaau8); |
| 73 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(t2.field3rust-analyzer cargo plain 0.2.3 tests/Dummy2#field3. == 0xaaaau16); |
| 74 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(t2.field4rust-analyzer cargo plain 0.2.3 tests/Dummy2#field4. == 0xaaaaaaaau32); |
| 75 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(t2.field5rust-analyzer cargo plain 0.2.3 tests/Dummy2#field5. == 0xbbbbbbbbccccddeeu64 || t2.field5rust-analyzer cargo plain 0.2.3 tests/Dummy2#field5. == 0xeeddccccbbbbbbbbu64); |
| 76 | |
| 77 | let sz = 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().::<Dummy2rust-analyzer cargo plain 0.2.3 tests/Dummy2#>(); |
| 78 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(t2.copy_from_bytes(&as_bytesrust-analyzer cargo plain 0.2.3 tests/as_bytes().(&t1)[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...sz -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). 1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().) == Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Error::TooShort)); |
| 79 | } |
| 80 | |
| 81 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 82 | fn basic_functionrust-analyzer cargo plain 0.2.3 tests/basic_function().() { |
| 83 | let t1 = Dummy1rust-analyzer cargo plain 0.2.3 tests/Dummy1# { |
| 84 | field1rust-analyzer cargo plain 0.2.3 tests/Dummy1#field1.: 0xaaaaaaaaaaaaaaaau64, |
| 85 | field2rust-analyzer cargo plain 0.2.3 tests/Dummy1#field2.: 0xbbbbbbbbu32, |
| 86 | field3rust-analyzer cargo plain 0.2.3 tests/Dummy1#field3.: 0xccccu16, |
| 87 | field4rust-analyzer cargo plain 0.2.3 tests/Dummy1#field4.: 0xddu8, |
| 88 | field5rust-analyzer cargo plain 0.2.3 tests/Dummy1#field5.: 0xeeu8, |
| 89 | }; |
| 90 | |
| 91 | let r1: &Dummy2rust-analyzer cargo plain 0.2.3 tests/Dummy2# = from_bytes(as_bytesrust-analyzer cargo plain 0.2.3 tests/as_bytes().(&t1)).unwrap(); |
| 92 | |
| 93 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(r1.field1rust-analyzer cargo plain 0.2.3 tests/Dummy2#field1. == 0xaau8); |
| 94 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(r1.field2rust-analyzer cargo plain 0.2.3 tests/Dummy2#field2. == 0xaau8); |
| 95 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(r1.field3rust-analyzer cargo plain 0.2.3 tests/Dummy2#field3. == 0xaaaau16); |
| 96 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(r1.field4rust-analyzer cargo plain 0.2.3 tests/Dummy2#field4. == 0xaaaaaaaau32); |
| 97 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(r1.field5rust-analyzer cargo plain 0.2.3 tests/Dummy2#field5. == 0xbbbbbbbbccccddeeu64 || r1.field5rust-analyzer cargo plain 0.2.3 tests/Dummy2#field5. == 0xeeddccccbbbbbbbbu64); |
| 98 | |
| 99 | let r2 = as_bytesrust-analyzer cargo plain 0.2.3 tests/as_bytes().(r1); |
| 100 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(r2.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() == 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().::<Dummy1rust-analyzer cargo plain 0.2.3 tests/Dummy1#>()); |
| 101 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(r2[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().5]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). == 0xaa); |
| 102 | |
| 103 | let size = r2.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(); |
| 104 | let r3 = as_bytesrust-analyzer cargo plain 0.2.3 tests/as_bytes().(r2); |
| 105 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(r3.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() == size); |
| 106 | |
| 107 | let r4 = Dummy1rust-analyzer cargo plain 0.2.3 tests/Dummy1#::from_bytes(r3).unwrap(); |
| 108 | |
| 109 | let r5 = from_bytes::<Dummy2rust-analyzer cargo plain 0.2.3 tests/Dummy2#>(as_bytesrust-analyzer cargo plain 0.2.3 tests/as_bytes().(r4)).unwrap(); |
| 110 | |
| 111 | { |
| 112 | let r6 = slice_from_bytes::<Dummy1rust-analyzer cargo plain 0.2.3 tests/Dummy1#>(as_bytesrust-analyzer cargo plain 0.2.3 tests/as_bytes().(r5)).unwrap(); |
| 113 | |
| 114 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(r6.len() == 1); |
| 115 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(t1 == r6[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().); |
| 116 | } |
| 117 | |
| 118 | let r7 = slice_from_bytes::<u64>(as_bytesrust-analyzer cargo plain 0.2.3 tests/as_bytes().(r5)).unwrap(); |
| 119 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(r7.len() == 2); |
| 120 | |
| 121 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(r7[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). == 0xaaaaaaaaaaaaaaaau64); |
| 122 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(r7[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). == 0xbbbbbbbbccccddeeu64 || r7[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). == 0xeeddccccbbbbbbbbu64); |
| 123 | } |