| 1 | use Errorrust-analyzer cargo plain 0.2.3 error/Error#; |
| 2 | |
| 3 | /// A trait for plain data types that can be safely read from a byte slice. |
| 4 | /// |
| 5 | /// A type can be [`Plain`](trait.Plain.html) if it is `#repr(C)` and only contains |
| 6 | /// data with no possible invalid values. Types that _can't_ be `Plain` |
| 7 | /// include, but are not limited to, `bool`, `char`, `enum`s, tuples, |
| 8 | /// pointers and references. |
| 9 | /// |
| 10 | /// At this moment, `Drop` types are also not legal, because |
| 11 | /// compiler adds a special "drop flag" into the type. This is slated |
| 12 | /// to change in the future. |
| 13 | /// |
| 14 | /// On the other hand, arrays of a `Plain` type, and |
| 15 | /// structures where all members are plain (and not `Drop`), are okay. |
| 16 | /// |
| 17 | /// Structures that are not `#repr(C)`, while not necessarily illegal |
| 18 | /// in principle, are largely useless because they don't have a stable |
| 19 | /// layout. For example, the compiler is allowed to reorder fields |
| 20 | /// arbitrarily. |
| 21 | /// |
| 22 | /// All methods of this trait are implemented automatically as wrappers |
| 23 | /// for crate-level funtions. |
| 24 | /// |
| 25 | pub unsafe trait Plainrust-analyzer cargo plain 0.2.3 plain/Plain# { |
| 26 | #[inline(always)] |
| 27 | fn from_bytesrust-analyzer cargo plain 0.2.3 plain/Plain#from_bytes().(bytes: &[u8]) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<&Self, Errorrust-analyzer cargo plain 0.2.3 error/Error#> |
| 28 | where |
| 29 | Self: Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#, |
| 30 | { |
| 31 | ::from_bytesrust-analyzer cargo plain 0.2.3 methods/from_bytes().(bytes) |
| 32 | } |
| 33 | |
| 34 | #[inline(always)] |
| 35 | fn slice_from_bytesrust-analyzer cargo plain 0.2.3 plain/Plain#slice_from_bytes().(bytes: &[u8]) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<&[Self], Errorrust-analyzer cargo plain 0.2.3 error/Error#> |
| 36 | where |
| 37 | Self: Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#, |
| 38 | { |
| 39 | ::slice_from_bytesrust-analyzer cargo plain 0.2.3 methods/slice_from_bytes().(bytes) |
| 40 | } |
| 41 | |
| 42 | #[inline(always)] |
| 43 | fn slice_from_bytes_lenrust-analyzer cargo plain 0.2.3 plain/Plain#slice_from_bytes_len().(bytes: &[u8], len: usize) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<&[Self], Errorrust-analyzer cargo plain 0.2.3 error/Error#> |
| 44 | where |
| 45 | Self: Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#, |
| 46 | { |
| 47 | ::slice_from_bytes_lenrust-analyzer cargo plain 0.2.3 methods/slice_from_bytes_len().(bytes, len) |
| 48 | } |
| 49 | |
| 50 | #[inline(always)] |
| 51 | fn from_mut_bytesrust-analyzer cargo plain 0.2.3 plain/Plain#from_mut_bytes().(bytes: &mut [u8]) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<&mut Self, Errorrust-analyzer cargo plain 0.2.3 error/Error#> |
| 52 | where |
| 53 | Self: Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#, |
| 54 | { |
| 55 | ::from_mut_bytesrust-analyzer cargo plain 0.2.3 methods/from_mut_bytes().(bytes) |
| 56 | } |
| 57 | |
| 58 | #[inline(always)] |
| 59 | fn slice_from_mut_bytesrust-analyzer cargo plain 0.2.3 plain/Plain#slice_from_mut_bytes().(bytes: &mut [u8]) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<&mut [Self], Errorrust-analyzer cargo plain 0.2.3 error/Error#> |
| 60 | where |
| 61 | Self: Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#, |
| 62 | { |
| 63 | ::slice_from_mut_bytesrust-analyzer cargo plain 0.2.3 methods/slice_from_mut_bytes().(bytes) |
| 64 | } |
| 65 | |
| 66 | #[inline(always)] |
| 67 | fn slice_from_mut_bytes_lenrust-analyzer cargo plain 0.2.3 plain/Plain#slice_from_mut_bytes_len().(bytes: &mut [u8], len: usize) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<&mut [Self], Errorrust-analyzer cargo plain 0.2.3 error/Error#> |
| 68 | where |
| 69 | Self: Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#, |
| 70 | { |
| 71 | ::slice_from_mut_bytes_lenrust-analyzer cargo plain 0.2.3 methods/slice_from_mut_bytes_len().(bytes, len) |
| 72 | } |
| 73 | |
| 74 | #[inline(always)] |
| 75 | fn copy_from_bytesrust-analyzer cargo plain 0.2.3 plain/Plain#copy_from_bytes().(&mut self, bytes: &[u8]) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo plain 0.2.3 error/Error#> { |
| 76 | ::copy_from_bytesrust-analyzer cargo plain 0.2.3 methods/copy_from_bytes().(self, bytes) |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | unsafe impl Plainrust-analyzer cargo plain 0.2.3 plain/Plain# for u8 {} |
| 81 | unsafe impl Plainrust-analyzer cargo plain 0.2.3 plain/Plain# for u16 {} |
| 82 | unsafe impl Plainrust-analyzer cargo plain 0.2.3 plain/Plain# for u32 {} |
| 83 | unsafe impl Plainrust-analyzer cargo plain 0.2.3 plain/Plain# for u64 {} |
| 84 | unsafe impl Plainrust-analyzer cargo plain 0.2.3 plain/Plain# for usize {} |
| 85 | |
| 86 | unsafe impl Plainrust-analyzer cargo plain 0.2.3 plain/Plain# for i8 {} |
| 87 | unsafe impl Plainrust-analyzer cargo plain 0.2.3 plain/Plain# for i16 {} |
| 88 | unsafe impl Plainrust-analyzer cargo plain 0.2.3 plain/Plain# for i32 {} |
| 89 | unsafe impl Plainrust-analyzer cargo plain 0.2.3 plain/Plain# for i64 {} |
| 90 | unsafe impl Plainrust-analyzer cargo plain 0.2.3 plain/Plain# for isize {} |
| 91 | |
| 92 | unsafe impl<S> Plainrust-analyzer cargo plain 0.2.3 plain/Plain# for [S] |
| 93 | where |
| 94 | S: Plainrust-analyzer cargo plain 0.2.3 plain/Plain#, |
| 95 | { |
| 96 | } |