| use zerocopy_derive::*; | ||
| // The only valid value of this type are the bytes `0xC0C0`. | ||
| #[derive(TryFromBytes, KnownLayout, Immutable)] | ||
| #[repr(u16)] | ||
| pub enum C0C0 { | ||
| _XC0C0 = 0xC0C0, | ||
| } | ||
| #[derive(FromBytes, KnownLayout, Immutable)] | ||
| #[repr(C, align(4))] | ||
| pub struct Packet<Magic> { | ||
| magic_number: Magic, | ||
| milk: u8, | ||
| mug_size: u8, | ||
| temperature: [u8; 5], | ||
| marshmallows: [[u8; 3]], | ||
| } | ||
| /// A packet begining with the magic number `0xC0C0`. | ||
| pub type CocoPacket = Packet<C0C0>; | ||
| /// A packet beginning with any two initialized bytes. | ||
| pub type LocoPacket = Packet<[u8; 2]>; |
| use zerocopy_derive::*; | ||
| // The only valid value of this type are the bytes `0xC0C0`. | ||
| #[derive(TryFromBytes, KnownLayout, Immutable)] | ||
| #[repr(u16)] | ||
| pub enum C0C0 { | ||
| _XC0C0 = 0xC0C0, | ||
| } | ||
| #[derive(FromBytes, KnownLayout, Immutable)] | ||
| #[repr(C, align(2))] | ||
| pub struct Packet<Magic> { | ||
| magic_number: Magic, | ||
| mug_size: u8, | ||
| temperature: u8, | ||
| marshmallows: [[u8; 2]], | ||
| } | ||
| /// A packet begining with the magic number `0xC0C0`. | ||
| pub type CocoPacket = Packet<C0C0>; | ||
| /// A packet beginning with any two initialized bytes. | ||
| pub type LocoPacket = Packet<[u8; 2]>; |
| use zerocopy_derive::*; | ||
| // The only valid value of this type are the bytes `0xC0C0`. | ||
| #[derive(TryFromBytes, KnownLayout, Immutable)] | ||
| #[repr(u16)] | ||
| pub enum C0C0 { | ||
| _XC0C0 = 0xC0C0, | ||
| } | ||
| #[derive(FromBytes, KnownLayout, Immutable)] | ||
| #[repr(C, align(2))] | ||
| pub struct Packet<Magic> { | ||
| magic_number: Magic, | ||
| mug_size: u8, | ||
| temperature: u8, | ||
| marshmallows: [u8; 2], | ||
| } | ||
| /// A packet begining with the magic number `0xC0C0`. | ||
| pub type CocoPacket = Packet<C0C0>; | ||
| /// A packet beginning with any two initialized bytes. | ||
| pub type LocoPacket = Packet<[u8; 2]>; |
| #[path = "formats/coco_static_size.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn bench_read_from_bytes_static_size(source: &[u8]) -> Option<format::LocoPacket> { | ||
| zerocopy::FromBytes::read_from_bytes(source).ok() | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| #[path = "formats/coco_static_size.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn bench_read_from_prefix_static_size(source: &[u8]) -> Option<format::LocoPacket> { | ||
| match zerocopy::FromBytes::read_from_prefix(source) { | ||
| Ok((packet, _rest)) => Some(packet), | ||
| _ => None, | ||
| } | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| #[path = "formats/coco_static_size.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn bench_read_from_suffix_static_size(source: &[u8]) -> Option<format::LocoPacket> { | ||
| match zerocopy::FromBytes::read_from_suffix(source) { | ||
| Ok((_rest, packet)) => Some(packet), | ||
| _ => None, | ||
| } | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| #[path = "formats/coco_dynamic_padding.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn bench_ref_from_bytes_dynamic_padding(source: &[u8]) -> Option<&format::LocoPacket> { | ||
| zerocopy::FromBytes::ref_from_bytes(source).ok() | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| #[path = "formats/coco_dynamic_size.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn bench_ref_from_bytes_dynamic_size(source: &[u8]) -> Option<&format::LocoPacket> { | ||
| zerocopy::FromBytes::ref_from_bytes(source).ok() | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| #[path = "formats/coco_static_size.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn bench_ref_from_bytes_static_size(source: &[u8]) -> Option<&format::LocoPacket> { | ||
| zerocopy::FromBytes::ref_from_bytes(source).ok() | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| #[path = "formats/coco_dynamic_padding.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn bench_ref_from_bytes_with_elems_dynamic_padding( | ||
| source: &[u8], | ||
| count: usize, | ||
| ) -> Option<&format::LocoPacket> { | ||
| zerocopy::FromBytes::ref_from_bytes_with_elems(source, count).ok() | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| #[path = "formats/coco_dynamic_size.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn bench_ref_from_bytes_with_elems_dynamic_size( | ||
| source: &[u8], | ||
| count: usize, | ||
| ) -> Option<&format::LocoPacket> { | ||
| zerocopy::FromBytes::ref_from_bytes_with_elems(source, count).ok() | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| #[path = "formats/coco_dynamic_padding.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn bench_ref_from_prefix_dynamic_padding(source: &[u8]) -> Option<&format::LocoPacket> { | ||
| match zerocopy::FromBytes::ref_from_prefix(source) { | ||
| Ok((packet, _rest)) => Some(packet), | ||
| _ => None, | ||
| } | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| #[path = "formats/coco_dynamic_size.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn bench_ref_from_prefix_dynamic_size(source: &[u8]) -> Option<&format::LocoPacket> { | ||
| match zerocopy::FromBytes::ref_from_prefix(source) { | ||
| Ok((packet, _rest)) => Some(packet), | ||
| _ => None, | ||
| } | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| #[path = "formats/coco_static_size.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn bench_ref_from_prefix_static_size(source: &[u8]) -> Option<&format::LocoPacket> { | ||
| match zerocopy::FromBytes::ref_from_prefix(source) { | ||
| Ok((packet, _rest)) => Some(packet), | ||
| _ => None, | ||
| } | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| #[path = "formats/coco_dynamic_padding.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn bench_ref_from_prefix_with_elems_dynamic_padding( | ||
| source: &[u8], | ||
| count: usize, | ||
| ) -> Option<&format::LocoPacket> { | ||
| match zerocopy::FromBytes::ref_from_prefix_with_elems(source, count) { | ||
| Ok((packet, _rest)) => Some(packet), | ||
| _ => None, | ||
| } | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| #[path = "formats/coco_dynamic_size.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn bench_ref_from_prefix_with_elems_dynamic_size( | ||
| source: &[u8], | ||
| count: usize, | ||
| ) -> Option<&format::LocoPacket> { | ||
| match zerocopy::FromBytes::ref_from_prefix_with_elems(source, count) { | ||
| Ok((packet, _rest)) => Some(packet), | ||
| _ => None, | ||
| } | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| #[path = "formats/coco_dynamic_padding.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn bench_ref_from_suffix_dynamic_padding(source: &[u8]) -> Option<&format::LocoPacket> { | ||
| match zerocopy::FromBytes::ref_from_suffix(source) { | ||
| Ok((_rest, packet)) => Some(packet), | ||
| _ => None, | ||
| } | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| #[path = "formats/coco_dynamic_size.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn bench_ref_from_suffix_dynamic_size(source: &[u8]) -> Option<&format::LocoPacket> { | ||
| match zerocopy::FromBytes::ref_from_suffix(source) { | ||
| Ok((_rest, packet)) => Some(packet), | ||
| _ => None, | ||
| } | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| #[path = "formats/coco_static_size.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn bench_ref_from_suffix_static_size(source: &[u8]) -> Option<&format::LocoPacket> { | ||
| match zerocopy::FromBytes::ref_from_suffix(source) { | ||
| Ok((_rest, packet)) => Some(packet), | ||
| _ => None, | ||
| } | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| #[path = "formats/coco_dynamic_padding.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn bench_ref_from_suffix_with_elems_dynamic_padding( | ||
| source: &[u8], | ||
| count: usize, | ||
| ) -> Option<&format::LocoPacket> { | ||
| match zerocopy::FromBytes::ref_from_suffix_with_elems(source, count) { | ||
| Ok((_rest, packet)) => Some(packet), | ||
| _ => None, | ||
| } | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| #[path = "formats/coco_dynamic_size.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn bench_ref_from_suffix_with_elems_dynamic_size( | ||
| source: &[u8], | ||
| count: usize, | ||
| ) -> Option<&format::LocoPacket> { | ||
| match zerocopy::FromBytes::ref_from_suffix_with_elems(source, count) { | ||
| Ok((_rest, packet)) => Some(packet), | ||
| _ => None, | ||
| } | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| use zerocopy_derive::*; | ||
| #[path = "formats/coco_dynamic_size.rs"] | ||
| mod format; | ||
| #[derive(IntoBytes, KnownLayout, Immutable)] | ||
| #[repr(C, align(2))] | ||
| struct MinimalViableSource { | ||
| header: [u8; 6], | ||
| trailer: [[u8; 2]], | ||
| } | ||
| #[unsafe(no_mangle)] | ||
| fn bench_transmute_ref_dynamic_size(source: &MinimalViableSource) -> &format::LocoPacket { | ||
| zerocopy::transmute_ref!(source) | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| use zerocopy_derive::*; | ||
| #[path = "formats/coco_static_size.rs"] | ||
| mod format; | ||
| #[derive(IntoBytes, KnownLayout, Immutable)] | ||
| #[repr(C, align(2))] | ||
| struct MinimalViableSource { | ||
| bytes: [u8; 6], | ||
| } | ||
| #[unsafe(no_mangle)] | ||
| fn bench_transmute_ref_static_size(source: &MinimalViableSource) -> &format::LocoPacket { | ||
| zerocopy::transmute_ref!(source) | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| use zerocopy::Unalign; | ||
| use zerocopy_derive::*; | ||
| #[path = "formats/coco_static_size.rs"] | ||
| mod format; | ||
| #[derive(IntoBytes, KnownLayout, Immutable)] | ||
| #[repr(C)] | ||
| struct MinimalViableSource { | ||
| bytes: [u8; 6], | ||
| } | ||
| #[unsafe(no_mangle)] | ||
| fn bench_transmute(source: MinimalViableSource) -> Unalign<format::LocoPacket> { | ||
| zerocopy::transmute!(source) | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| #[path = "formats/coco_static_size.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn bench_try_read_from_bytes_static_size(source: &[u8]) -> Option<format::CocoPacket> { | ||
| zerocopy::TryFromBytes::try_read_from_bytes(source).ok() | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| #[path = "formats/coco_static_size.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn bench_try_read_from_prefix_static_size(source: &[u8]) -> Option<format::CocoPacket> { | ||
| match zerocopy::TryFromBytes::try_read_from_prefix(source) { | ||
| Ok((packet, _rest)) => Some(packet), | ||
| _ => None, | ||
| } | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| #[path = "formats/coco_static_size.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn bench_try_read_from_suffix_static_size(source: &[u8]) -> Option<format::CocoPacket> { | ||
| match zerocopy::TryFromBytes::try_read_from_suffix(source) { | ||
| Ok((_rest, packet)) => Some(packet), | ||
| _ => None, | ||
| } | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| #[path = "formats/coco_dynamic_padding.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn bench_try_ref_from_bytes_dynamic_padding(source: &[u8]) -> Option<&format::CocoPacket> { | ||
| zerocopy::TryFromBytes::try_ref_from_bytes(source).ok() | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| #[path = "formats/coco_dynamic_size.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn bench_try_ref_from_bytes_dynamic_size(source: &[u8]) -> Option<&format::CocoPacket> { | ||
| zerocopy::TryFromBytes::try_ref_from_bytes(source).ok() | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| #[path = "formats/coco_static_size.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn bench_try_ref_from_bytes_static_size(source: &[u8]) -> Option<&format::CocoPacket> { | ||
| zerocopy::TryFromBytes::try_ref_from_bytes(source).ok() | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| #[path = "formats/coco_dynamic_padding.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn bench_try_ref_from_bytes_with_elems_dynamic_padding( | ||
| source: &[u8], | ||
| count: usize, | ||
| ) -> Option<&format::CocoPacket> { | ||
| zerocopy::TryFromBytes::try_ref_from_bytes_with_elems(source, count).ok() | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| #[path = "formats/coco_dynamic_size.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn bench_try_ref_from_bytes_with_elems_dynamic_size( | ||
| source: &[u8], | ||
| count: usize, | ||
| ) -> Option<&format::CocoPacket> { | ||
| zerocopy::TryFromBytes::try_ref_from_bytes_with_elems(source, count).ok() | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| #[path = "formats/coco_dynamic_padding.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn bench_try_ref_from_prefix_dynamic_padding(source: &[u8]) -> Option<&format::CocoPacket> { | ||
| match zerocopy::TryFromBytes::try_ref_from_prefix(source) { | ||
| Ok((packet, _rest)) => Some(packet), | ||
| _ => None, | ||
| } | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| #[path = "formats/coco_dynamic_size.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn bench_try_ref_from_prefix_dynamic_size(source: &[u8]) -> Option<&format::CocoPacket> { | ||
| match zerocopy::TryFromBytes::try_ref_from_prefix(source) { | ||
| Ok((packet, _rest)) => Some(packet), | ||
| _ => None, | ||
| } | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| #[path = "formats/coco_static_size.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn bench_try_ref_from_prefix_static_size(source: &[u8]) -> Option<&format::CocoPacket> { | ||
| match zerocopy::TryFromBytes::try_ref_from_prefix(source) { | ||
| Ok((packet, _rest)) => Some(packet), | ||
| _ => None, | ||
| } | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| #[path = "formats/coco_dynamic_padding.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn bench_try_ref_from_prefix_with_elems_dynamic_padding( | ||
| source: &[u8], | ||
| count: usize, | ||
| ) -> Option<&format::CocoPacket> { | ||
| match zerocopy::TryFromBytes::try_ref_from_prefix_with_elems(source, count) { | ||
| Ok((packet, _rest)) => Some(packet), | ||
| _ => None, | ||
| } | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| #[path = "formats/coco_dynamic_size.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn bench_try_ref_from_prefix_with_elems_dynamic_size( | ||
| source: &[u8], | ||
| count: usize, | ||
| ) -> Option<&format::CocoPacket> { | ||
| match zerocopy::TryFromBytes::try_ref_from_prefix_with_elems(source, count) { | ||
| Ok((packet, _rest)) => Some(packet), | ||
| _ => None, | ||
| } | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| #[path = "formats/coco_dynamic_padding.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn bench_try_ref_from_suffix_dynamic_padding(source: &[u8]) -> Option<&format::CocoPacket> { | ||
| match zerocopy::TryFromBytes::try_ref_from_suffix(source) { | ||
| Ok((_rest, packet)) => Some(packet), | ||
| _ => None, | ||
| } | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| #[path = "formats/coco_dynamic_size.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn bench_try_ref_from_suffix_dynamic_size(source: &[u8]) -> Option<&format::CocoPacket> { | ||
| match zerocopy::TryFromBytes::try_ref_from_suffix(source) { | ||
| Ok((_rest, packet)) => Some(packet), | ||
| _ => None, | ||
| } | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| #[path = "formats/coco_static_size.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn bench_try_ref_from_suffix_static_size(source: &[u8]) -> Option<&format::CocoPacket> { | ||
| match zerocopy::TryFromBytes::try_ref_from_suffix(source) { | ||
| Ok((_rest, packet)) => Some(packet), | ||
| _ => None, | ||
| } | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| #[path = "formats/coco_dynamic_padding.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn bench_try_ref_from_suffix_with_elems_dynamic_padding( | ||
| source: &[u8], | ||
| count: usize, | ||
| ) -> Option<&format::CocoPacket> { | ||
| match zerocopy::TryFromBytes::try_ref_from_suffix_with_elems(source, count) { | ||
| Ok((_rest, packet)) => Some(packet), | ||
| _ => None, | ||
| } | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| #[path = "formats/coco_dynamic_size.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn bench_try_ref_from_suffix_with_elems_dynamic_size( | ||
| source: &[u8], | ||
| count: usize, | ||
| ) -> Option<&format::CocoPacket> { | ||
| match zerocopy::TryFromBytes::try_ref_from_suffix_with_elems(source, count) { | ||
| Ok((_rest, packet)) => Some(packet), | ||
| _ => None, | ||
| } | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| use zerocopy_derive::*; | ||
| #[path = "formats/coco_dynamic_size.rs"] | ||
| mod format; | ||
| #[derive(IntoBytes, KnownLayout, Immutable)] | ||
| #[repr(C, align(2))] | ||
| struct MinimalViableSource { | ||
| header: [u8; 6], | ||
| trailer: [[u8; 2]], | ||
| } | ||
| #[unsafe(no_mangle)] | ||
| fn bench_try_transmute_ref_dynamic_size( | ||
| source: &MinimalViableSource, | ||
| ) -> Option<&format::CocoPacket> { | ||
| zerocopy::try_transmute_ref!(source).ok() | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| use zerocopy_derive::*; | ||
| #[path = "formats/coco_static_size.rs"] | ||
| mod format; | ||
| #[derive(IntoBytes, KnownLayout, Immutable)] | ||
| #[repr(C, align(2))] | ||
| struct MinimalViableSource { | ||
| bytes: [u8; 6], | ||
| } | ||
| #[unsafe(no_mangle)] | ||
| fn bench_try_transmute_ref_static_size( | ||
| source: &MinimalViableSource, | ||
| ) -> Option<&format::CocoPacket> { | ||
| zerocopy::try_transmute_ref!(source).ok() | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| use zerocopy::Unalign; | ||
| use zerocopy_derive::*; | ||
| #[path = "formats/coco_static_size.rs"] | ||
| mod format; | ||
| #[derive(IntoBytes, KnownLayout, Immutable)] | ||
| #[repr(C)] | ||
| struct MinimalViableSource { | ||
| bytes: [u8; 6], | ||
| } | ||
| #[unsafe(no_mangle)] | ||
| fn bench_try_transmute(source: MinimalViableSource) -> Option<Unalign<format::CocoPacket>> { | ||
| zerocopy::try_transmute!(source).ok() | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| { | ||
| "git": { | ||
| "sha1": "dbef2724b5106bab506dd3ce0e53b4ac97d05c61" | ||
| "sha1": "fc7362493d052b276d88f790dc9e3b5cba564273" | ||
| }, | ||
| "path_in_vcs": "" | ||
| } |
+3
-3
@@ -90,3 +90,3 @@ # This file is automatically @generated by Cargo. | ||
| name = "zerocopy" | ||
| version = "0.8.41-alpha" | ||
| version = "0.8.41" | ||
| dependencies = [ | ||
@@ -103,5 +103,5 @@ "elain", | ||
| name = "zerocopy-derive" | ||
| version = "0.8.41-alpha" | ||
| version = "0.8.41" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "065608df236bc2b0b7df6efb2784fd66b72fbff6422ea98c0656534695d41151" | ||
| checksum = "3545ea9e86d12ab9bba9fcd99b54c1556fd3199007def5a03c375623d05fac1c" | ||
| dependencies = [ | ||
@@ -108,0 +108,0 @@ "proc-macro2", |
+144
-32
@@ -16,3 +16,3 @@ # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO | ||
| name = "zerocopy" | ||
| version = "0.8.41-alpha" | ||
| version = "0.8.41" | ||
| authors = [ | ||
@@ -105,59 +105,171 @@ "Joshua Liebow-Feeser <joshlf@google.com>", | ||
| [[bench]] | ||
| name = "ref_from_bytes" | ||
| path = "benches/ref_from_bytes.rs" | ||
| name = "read_from_bytes" | ||
| path = "benches/read_from_bytes.rs" | ||
| [[bench]] | ||
| name = "ref_from_bytes_with_elems" | ||
| path = "benches/ref_from_bytes_with_elems.rs" | ||
| name = "read_from_prefix" | ||
| path = "benches/read_from_prefix.rs" | ||
| [[bench]] | ||
| name = "ref_from_prefix" | ||
| path = "benches/ref_from_prefix.rs" | ||
| name = "read_from_suffix" | ||
| path = "benches/read_from_suffix.rs" | ||
| [[bench]] | ||
| name = "ref_from_prefix_with_elems" | ||
| path = "benches/ref_from_prefix_with_elems.rs" | ||
| name = "ref_from_bytes_dynamic_padding" | ||
| path = "benches/ref_from_bytes_dynamic_padding.rs" | ||
| [[bench]] | ||
| name = "ref_from_suffix" | ||
| path = "benches/ref_from_suffix.rs" | ||
| name = "ref_from_bytes_dynamic_size" | ||
| path = "benches/ref_from_bytes_dynamic_size.rs" | ||
| [[bench]] | ||
| name = "ref_from_suffix_with_elems" | ||
| path = "benches/ref_from_suffix_with_elems.rs" | ||
| name = "ref_from_bytes_static_size" | ||
| path = "benches/ref_from_bytes_static_size.rs" | ||
| [[bench]] | ||
| name = "transmute_ref" | ||
| path = "benches/transmute_ref.rs" | ||
| name = "ref_from_bytes_with_elems_dynamic_padding" | ||
| path = "benches/ref_from_bytes_with_elems_dynamic_padding.rs" | ||
| [[bench]] | ||
| name = "try_ref_from_bytes" | ||
| path = "benches/try_ref_from_bytes.rs" | ||
| name = "ref_from_bytes_with_elems_dynamic_size" | ||
| path = "benches/ref_from_bytes_with_elems_dynamic_size.rs" | ||
| [[bench]] | ||
| name = "try_ref_from_bytes_with_elems" | ||
| path = "benches/try_ref_from_bytes_with_elems.rs" | ||
| name = "ref_from_prefix_dynamic_padding" | ||
| path = "benches/ref_from_prefix_dynamic_padding.rs" | ||
| [[bench]] | ||
| name = "try_ref_from_prefix" | ||
| path = "benches/try_ref_from_prefix.rs" | ||
| name = "ref_from_prefix_dynamic_size" | ||
| path = "benches/ref_from_prefix_dynamic_size.rs" | ||
| [[bench]] | ||
| name = "try_ref_from_prefix_with_elems" | ||
| path = "benches/try_ref_from_prefix_with_elems.rs" | ||
| name = "ref_from_prefix_static_size" | ||
| path = "benches/ref_from_prefix_static_size.rs" | ||
| [[bench]] | ||
| name = "try_ref_from_suffix" | ||
| path = "benches/try_ref_from_suffix.rs" | ||
| name = "ref_from_prefix_with_elems_dynamic_padding" | ||
| path = "benches/ref_from_prefix_with_elems_dynamic_padding.rs" | ||
| [[bench]] | ||
| name = "try_ref_from_suffix_with_elems" | ||
| path = "benches/try_ref_from_suffix_with_elems.rs" | ||
| name = "ref_from_prefix_with_elems_dynamic_size" | ||
| path = "benches/ref_from_prefix_with_elems_dynamic_size.rs" | ||
| [[bench]] | ||
| name = "try_transmute_ref" | ||
| path = "benches/try_transmute_ref.rs" | ||
| name = "ref_from_suffix_dynamic_padding" | ||
| path = "benches/ref_from_suffix_dynamic_padding.rs" | ||
| [[bench]] | ||
| name = "ref_from_suffix_dynamic_size" | ||
| path = "benches/ref_from_suffix_dynamic_size.rs" | ||
| [[bench]] | ||
| name = "ref_from_suffix_static_size" | ||
| path = "benches/ref_from_suffix_static_size.rs" | ||
| [[bench]] | ||
| name = "ref_from_suffix_with_elems_dynamic_padding" | ||
| path = "benches/ref_from_suffix_with_elems_dynamic_padding.rs" | ||
| [[bench]] | ||
| name = "ref_from_suffix_with_elems_dynamic_size" | ||
| path = "benches/ref_from_suffix_with_elems_dynamic_size.rs" | ||
| [[bench]] | ||
| name = "transmute" | ||
| path = "benches/transmute.rs" | ||
| [[bench]] | ||
| name = "transmute_ref_dynamic_size" | ||
| path = "benches/transmute_ref_dynamic_size.rs" | ||
| [[bench]] | ||
| name = "transmute_ref_static_size" | ||
| path = "benches/transmute_ref_static_size.rs" | ||
| [[bench]] | ||
| name = "try_read_from_bytes" | ||
| path = "benches/try_read_from_bytes.rs" | ||
| [[bench]] | ||
| name = "try_read_from_prefix" | ||
| path = "benches/try_read_from_prefix.rs" | ||
| [[bench]] | ||
| name = "try_read_from_suffix" | ||
| path = "benches/try_read_from_suffix.rs" | ||
| [[bench]] | ||
| name = "try_ref_from_bytes_dynamic_padding" | ||
| path = "benches/try_ref_from_bytes_dynamic_padding.rs" | ||
| [[bench]] | ||
| name = "try_ref_from_bytes_dynamic_size" | ||
| path = "benches/try_ref_from_bytes_dynamic_size.rs" | ||
| [[bench]] | ||
| name = "try_ref_from_bytes_static_size" | ||
| path = "benches/try_ref_from_bytes_static_size.rs" | ||
| [[bench]] | ||
| name = "try_ref_from_bytes_with_elems_dynamic_padding" | ||
| path = "benches/try_ref_from_bytes_with_elems_dynamic_padding.rs" | ||
| [[bench]] | ||
| name = "try_ref_from_bytes_with_elems_dynamic_size" | ||
| path = "benches/try_ref_from_bytes_with_elems_dynamic_size.rs" | ||
| [[bench]] | ||
| name = "try_ref_from_prefix_dynamic_padding" | ||
| path = "benches/try_ref_from_prefix_dynamic_padding.rs" | ||
| [[bench]] | ||
| name = "try_ref_from_prefix_dynamic_size" | ||
| path = "benches/try_ref_from_prefix_dynamic_size.rs" | ||
| [[bench]] | ||
| name = "try_ref_from_prefix_static_size" | ||
| path = "benches/try_ref_from_prefix_static_size.rs" | ||
| [[bench]] | ||
| name = "try_ref_from_prefix_with_elems_dynamic_padding" | ||
| path = "benches/try_ref_from_prefix_with_elems_dynamic_padding.rs" | ||
| [[bench]] | ||
| name = "try_ref_from_prefix_with_elems_dynamic_size" | ||
| path = "benches/try_ref_from_prefix_with_elems_dynamic_size.rs" | ||
| [[bench]] | ||
| name = "try_ref_from_suffix_dynamic_padding" | ||
| path = "benches/try_ref_from_suffix_dynamic_padding.rs" | ||
| [[bench]] | ||
| name = "try_ref_from_suffix_dynamic_size" | ||
| path = "benches/try_ref_from_suffix_dynamic_size.rs" | ||
| [[bench]] | ||
| name = "try_ref_from_suffix_static_size" | ||
| path = "benches/try_ref_from_suffix_static_size.rs" | ||
| [[bench]] | ||
| name = "try_ref_from_suffix_with_elems_dynamic_padding" | ||
| path = "benches/try_ref_from_suffix_with_elems_dynamic_padding.rs" | ||
| [[bench]] | ||
| name = "try_ref_from_suffix_with_elems_dynamic_size" | ||
| path = "benches/try_ref_from_suffix_with_elems_dynamic_size.rs" | ||
| [[bench]] | ||
| name = "try_transmute" | ||
| path = "benches/try_transmute.rs" | ||
| [[bench]] | ||
| name = "try_transmute_ref_dynamic_size" | ||
| path = "benches/try_transmute_ref_dynamic_size.rs" | ||
| [[bench]] | ||
| name = "try_transmute_ref_static_size" | ||
| path = "benches/try_transmute_ref_static_size.rs" | ||
| [dependencies.zerocopy-derive] | ||
| version = "=0.8.41-alpha" | ||
| version = "=0.8.41" | ||
| optional = true | ||
@@ -183,5 +295,5 @@ | ||
| [dev-dependencies.zerocopy-derive] | ||
| version = "=0.8.41-alpha" | ||
| version = "=0.8.41" | ||
| [target."cfg(any())".dependencies.zerocopy-derive] | ||
| version = "=0.8.41-alpha" | ||
| version = "=0.8.41" |
@@ -13,3 +13,3 @@ /* | ||
| display: grid; | ||
| grid-template-columns: repeat(3, minmax(200px, 1fr)); | ||
| grid-template-columns: repeat(var(--arity), minmax(200px, 1fr)); | ||
| grid-template-rows: auto 1fr; | ||
@@ -19,6 +19,8 @@ column-gap: 1rem; | ||
| .codegen-tabs:not(:has(details[open]))::after { | ||
| .codegen-tabs:not(:has(> details[open]))::after { | ||
| grid-column: 1/-1; | ||
| content: 'Click one of the above headers to expand its contents.'; | ||
| font-style: italic; | ||
| font-size: small; | ||
| text-align: center; | ||
| } | ||
@@ -43,3 +45,3 @@ | ||
| .codegen-tabs details[open] :is(summary) { | ||
| .codegen-tabs details[open] > summary { | ||
| background-color: var(--code-block-background-color); | ||
@@ -46,0 +48,0 @@ border-bottom-color: var(--target-border-color); |
+169
-63
@@ -378,2 +378,3 @@ // Copyright 2023 The Fuchsia Authors | ||
| #[cfg_attr(__ZEROCOPY_INTERNAL_USE_ONLY_DEV_MODE, macro_export)] // Used in `doctests.rs` | ||
| #[doc(hidden)] | ||
| macro_rules! impl_or_verify { | ||
@@ -840,2 +841,10 @@ // The following two match arms follow the same pattern as their | ||
| /// Extracts the contents of doc comments. | ||
| #[allow(unused)] | ||
| macro_rules! docstring { | ||
| ($(#[doc = $content:expr])*) => { | ||
| concat!($($content, "\n",)*) | ||
| } | ||
| } | ||
| /// Generate a rustdoc-style header with `$name` as the HTML ID for the 'Code | ||
@@ -845,6 +854,8 @@ /// Generation' section of documentation. | ||
| macro_rules! codegen_header { | ||
| ($name:expr) => { | ||
| ($level:expr, $name:expr) => { | ||
| concat!( | ||
| " | ||
| <h5 id='method.", | ||
| <", | ||
| $level, | ||
| " id='method.", | ||
| $name, | ||
@@ -856,3 +867,5 @@ ".codegen'> | ||
| Code Generation | ||
| </h5> | ||
| </", | ||
| $level, | ||
| "> | ||
| " | ||
@@ -863,73 +876,166 @@ ) | ||
| /// Generate the HTML for the tabulated portion of the 'Code Generation' | ||
| /// documentation. Consumes the name of the format file and benchmark. | ||
| /// Generates HTML tabs. | ||
| #[rustfmt::skip] | ||
| #[allow(unused)] | ||
| macro_rules! codegen_tabs { | ||
| (format = $format:expr, bench = $name:expr) => { | ||
| concat!( | ||
| " | ||
| <div class='codegen-tabs'> | ||
| <details name='tab-", | ||
| $name, | ||
| "' style='--n: 1'> | ||
| <summary> | ||
| <h6>Format</h6> | ||
| </summary> | ||
| macro_rules! tabs { | ||
| ( | ||
| name = $name:expr, | ||
| arity = $arity:literal, | ||
| $([ | ||
| $($open:ident)? | ||
| @index $n:literal | ||
| @title $title:literal | ||
| $(#[doc = $content:expr])* | ||
| ]),* | ||
| ) => { | ||
| concat!(" | ||
| <div class='codegen-tabs' style='--arity: ", $arity ,"'>", $(concat!(" | ||
| <details name='tab-", $name,"' style='--n: ", $n ,"'", $(stringify!($open),)*"> | ||
| <summary><h6>", $title, "</h6></summary> | ||
| <div> | ||
| ```ignore | ||
| ", | ||
| include_str!(concat!("../benches/formats/", $format, ".rs")), | ||
| "``` | ||
| ", $($content, "\n",)* " | ||
| \ | ||
| </div> | ||
| </details> | ||
| <details name='tab-", | ||
| $name, | ||
| "' style='--n: 2'> | ||
| <summary> | ||
| <h6>Benchmark</h6> | ||
| </summary> | ||
| <div> | ||
| </details>"),)* | ||
| "</div>") | ||
| } | ||
| } | ||
| ```ignore | ||
| ", | ||
| include_str!(concat!("../benches/", $name, ".rs")), | ||
| "``` | ||
| \ | ||
| </div> | ||
| </details> | ||
| <details name='tab-", | ||
| $name, | ||
| "' style='--n: 3'> | ||
| <summary> | ||
| <h6>Machine Code Analysis</h6> | ||
| </summary> | ||
| <div> | ||
| /// Generates the HTML for a single benchmark example. | ||
| #[allow(unused)] | ||
| macro_rules! codegen_example { | ||
| (format = $format:expr, bench = $bench:expr) => { | ||
| tabs!( | ||
| name = $bench, | ||
| arity = 4, | ||
| [ | ||
| @index 1 | ||
| @title "Format" | ||
| /// ```ignore | ||
| #[doc = include_str!(concat!("../benches/formats/", $format, ".rs"))] | ||
| /// ``` | ||
| ], | ||
| [ | ||
| @index 2 | ||
| @title "Benchmark" | ||
| /// ```ignore | ||
| #[doc = include_str!(concat!("../benches/", $bench, ".rs"))] | ||
| /// ``` | ||
| ], | ||
| [ | ||
| open | ||
| @index 3 | ||
| @title "Assembly" | ||
| /// ```plain | ||
| #[doc = include_str!(concat!("../benches/", $bench, ".x86-64"))] | ||
| /// ``` | ||
| ], | ||
| [ | ||
| @index 4 | ||
| @title "Machine Code Analysis" | ||
| /// ```plain | ||
| #[doc = include_str!(concat!("../benches/", $bench, ".x86-64.mca"))] | ||
| /// ``` | ||
| ] | ||
| ) | ||
| } | ||
| } | ||
| ### Replication | ||
| /// Generate the HTML for a suite of benchmark examples. | ||
| #[allow(unused)] | ||
| macro_rules! codegen_example_suite { | ||
| ( | ||
| bench = $bench:expr, | ||
| format = $format:expr, | ||
| arity = $arity:literal, | ||
| $([ | ||
| $($open:ident)? | ||
| @index $index:literal | ||
| @title $title:literal | ||
| @variant $variant:literal | ||
| ]),* | ||
| ) => { | ||
| tabs!( | ||
| name = $bench, | ||
| arity = $arity, | ||
| $([ | ||
| $($open)* | ||
| @index $index | ||
| @title $title | ||
| #[doc = codegen_example!( | ||
| format = concat!($format, "_", $variant), | ||
| bench = concat!($bench, "_", $variant) | ||
| )] | ||
| ]),* | ||
| ) | ||
| } | ||
| } | ||
| You may replicate this analysis on your device with [`cargo-show-asm`] by running: | ||
| /// Generates the string for code generation preamble. | ||
| #[allow(unused)] | ||
| macro_rules! codegen_preamble { | ||
| () => { | ||
| docstring!( | ||
| /// | ||
| /// This abstraction is safe and cheap, but does not necessarily | ||
| /// have zero runtime cost. The codegen you experience in practice | ||
| /// will depend on optimization level, the layout of the destination | ||
| /// type, and what the compiler can prove about the source. | ||
| /// | ||
| ) | ||
| } | ||
| } | ||
| [`cargo-show-asm`]: https://github.com/pacak/cargo-show-asm | ||
| ```bash | ||
| cargo asm --bench ", | ||
| $name, | ||
| " codegen_test --mca | ||
| ``` | ||
| ### Results | ||
| ```plain | ||
| ", | ||
| include_str!(concat!("../benches/", $name, ".x86-64.mca")), | ||
| "``` | ||
| \ | ||
| </div> | ||
| </details> | ||
| </div> | ||
| " | ||
| /// Generates the HTML for code generation documentation. | ||
| #[allow(unused)] | ||
| macro_rules! codegen_section { | ||
| ( | ||
| header = $level:expr, | ||
| bench = $bench:expr, | ||
| format = $format:expr, | ||
| arity = $arity:literal, | ||
| $([ | ||
| $($open:ident)? | ||
| @index $index:literal | ||
| @title $title:literal | ||
| @variant $variant:literal | ||
| ]),* | ||
| ) => { | ||
| concat!( | ||
| codegen_header!($level, $bench), | ||
| codegen_preamble!(), | ||
| docstring!( | ||
| /// | ||
| /// The below examples illustrate typical codegen for | ||
| /// increasingly complex types: | ||
| /// | ||
| ), | ||
| codegen_example_suite!( | ||
| bench = $bench, | ||
| format = $format, | ||
| arity = $arity, | ||
| $([ | ||
| $($open)* | ||
| @index $index | ||
| @title $title | ||
| @variant $variant | ||
| ]),* | ||
| ) | ||
| ) | ||
| }; | ||
| ( | ||
| header = $level:expr, | ||
| bench = $bench:expr, | ||
| format = $format:expr, | ||
| ) => { | ||
| concat!( | ||
| codegen_header!($level, $bench), | ||
| codegen_preamble!(), | ||
| codegen_example!( | ||
| format = $format, | ||
| bench = $bench | ||
| ) | ||
| ) | ||
| } | ||
| } |
+74
-37
@@ -13,48 +13,85 @@ // Copyright 2026 The Fuchsia Authors | ||
| enum Directive { | ||
| Asm, | ||
| Mca, | ||
| } | ||
| impl Directive { | ||
| fn arg(&self) -> &'static str { | ||
| match self { | ||
| Directive::Asm => "--asm", | ||
| Directive::Mca => "--mca", | ||
| } | ||
| } | ||
| fn ext(&self) -> &'static str { | ||
| match self { | ||
| Directive::Asm => "", | ||
| Directive::Mca => ".mca", | ||
| } | ||
| } | ||
| } | ||
| fn run_codegen_test(bench_name: &str, target_cpu: &str, bless: bool) { | ||
| println!("Testing {bench_name}.{target_cpu}"); | ||
| let manifest_path = env!("CARGO_MANIFEST_PATH"); | ||
| let target_dir = env!("CARGO_TARGET_DIR"); | ||
| let output = Command::new("cargo") | ||
| .args([ | ||
| "asm", | ||
| "-p", | ||
| "zerocopy", | ||
| "--manifest-path", | ||
| manifest_path, | ||
| "--target-dir", | ||
| target_dir, | ||
| "--bench", | ||
| bench_name, | ||
| "--target-cpu", | ||
| target_cpu, | ||
| "--mca", | ||
| "codegen_test", | ||
| ]) | ||
| .output() | ||
| .expect("failed to execute process"); | ||
| let cargo_asm = |directive: &Directive| { | ||
| Command::new("cargo") | ||
| .args([ | ||
| "asm", | ||
| "-p", | ||
| "zerocopy", | ||
| "--manifest-path", | ||
| manifest_path, | ||
| "--target-dir", | ||
| target_dir, | ||
| "--bench", | ||
| bench_name, | ||
| "--target-cpu", | ||
| target_cpu, | ||
| "--simplify", | ||
| directive.arg(), | ||
| &format!("bench_{bench_name}"), | ||
| ]) | ||
| .output() | ||
| .expect("failed to execute process") | ||
| }; | ||
| let actual_result = output.stdout; | ||
| let test_directive = |directive: Directive| { | ||
| let output = cargo_asm(&directive); | ||
| let actual_result = output.stdout; | ||
| if !(output.status.success()) { | ||
| panic!("{}", String::from_utf8_lossy(&output.stderr)); | ||
| } | ||
| if !(output.status.success()) { | ||
| panic!( | ||
| "{}\n{}", | ||
| String::from_utf8_lossy(&actual_result), | ||
| String::from_utf8_lossy(&output.stderr) | ||
| ); | ||
| } | ||
| let expected_file_path = { | ||
| let mut path: PathBuf = env!("CARGO_MANIFEST_DIR").into(); | ||
| path.push("benches"); | ||
| let file_name = format!("{bench_name}.{target_cpu}.mca"); | ||
| path.push(file_name); | ||
| path | ||
| let expected_file_path = { | ||
| let ext = directive.ext(); | ||
| let mut path: PathBuf = env!("CARGO_MANIFEST_DIR").into(); | ||
| path.push("benches"); | ||
| let file_name = format!("{bench_name}.{target_cpu}{ext}",); | ||
| path.push(file_name); | ||
| path | ||
| }; | ||
| if bless { | ||
| std::fs::write(expected_file_path, &actual_result).unwrap(); | ||
| } else { | ||
| let expected_result = std::fs::read(expected_file_path).unwrap_or_default(); | ||
| if actual_result != expected_result { | ||
| let expected = String::from_utf8_lossy(&expected_result[..]); | ||
| panic!("Bless codegen tests with BLESS=1\nGot unexpected output:\n{}", expected); | ||
| } | ||
| } | ||
| }; | ||
| if bless { | ||
| std::fs::write(expected_file_path, &actual_result).unwrap(); | ||
| } else { | ||
| let expected_result = std::fs::read(expected_file_path).unwrap_or_default(); | ||
| if actual_result != expected_result { | ||
| let expected = String::from_utf8_lossy(&expected_result[..]); | ||
| panic!("Bless codegen tests with BLESS=1\nGot unexpected output:\n{}", expected); | ||
| } | ||
| } | ||
| test_directive(Directive::Asm); | ||
| test_directive(Directive::Mca); | ||
| } | ||
@@ -61,0 +98,0 @@ |
| use zerocopy_derive::*; | ||
| // The only valid value of this type are the bytes `0xC0C0`. | ||
| #[derive(TryFromBytes, KnownLayout, Immutable)] | ||
| #[repr(u16)] | ||
| pub enum C0C0 { | ||
| _XC0C0 = 0xC0C0, | ||
| } | ||
| #[derive(FromBytes, KnownLayout, Immutable)] | ||
| #[repr(C, align(2))] | ||
| pub struct Packet<Magic> { | ||
| magic_number: Magic, | ||
| mug_size: u8, | ||
| temperature: u8, | ||
| marshmallows: [[u8; 2]], | ||
| } | ||
| /// A packet begining with the magic number `0xC0C0`. | ||
| pub type CocoPacket = Packet<C0C0>; | ||
| /// A packet beginning with any two initialized bytes. | ||
| pub type LocoPacket = Packet<[u8; 2]>; |
| #[path = "formats/coco.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn codegen_test(source: &[u8], count: usize) -> Option<&format::LocoPacket> { | ||
| zerocopy::FromBytes::ref_from_bytes_with_elems(source, count).ok() | ||
| } |
Sorry, the diff of this file is not supported yet
| #[path = "formats/coco.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn codegen_test(source: &[u8]) -> Option<&format::LocoPacket> { | ||
| zerocopy::FromBytes::ref_from_bytes(source).ok() | ||
| } |
Sorry, the diff of this file is not supported yet
| #[path = "formats/coco.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn codegen_test(source: &[u8], count: usize) -> Option<&format::LocoPacket> { | ||
| match zerocopy::FromBytes::ref_from_prefix_with_elems(source, count) { | ||
| Ok((packet, _rest)) => Some(packet), | ||
| _ => None, | ||
| } | ||
| } |
Sorry, the diff of this file is not supported yet
| #[path = "formats/coco.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn codegen_test(source: &[u8]) -> Option<&format::LocoPacket> { | ||
| match zerocopy::FromBytes::ref_from_prefix(source) { | ||
| Ok((packet, _rest)) => Some(packet), | ||
| _ => None, | ||
| } | ||
| } |
Sorry, the diff of this file is not supported yet
| #[path = "formats/coco.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn codegen_test(source: &[u8], count: usize) -> Option<&format::LocoPacket> { | ||
| match zerocopy::FromBytes::ref_from_suffix_with_elems(source, count) { | ||
| Ok((_rest, packet)) => Some(packet), | ||
| _ => None, | ||
| } | ||
| } |
Sorry, the diff of this file is not supported yet
| #[path = "formats/coco.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn codegen_test(source: &[u8]) -> Option<&format::LocoPacket> { | ||
| match zerocopy::FromBytes::ref_from_suffix(source) { | ||
| Ok((_rest, packet)) => Some(packet), | ||
| _ => None, | ||
| } | ||
| } |
Sorry, the diff of this file is not supported yet
| use zerocopy_derive::*; | ||
| #[path = "formats/coco.rs"] | ||
| mod format; | ||
| #[derive(IntoBytes, KnownLayout, Immutable)] | ||
| #[repr(C, align(2))] | ||
| struct MinimalViableSource { | ||
| header: [u8; 4], | ||
| trailer: [[u8; 2]], | ||
| } | ||
| #[unsafe(no_mangle)] | ||
| fn codegen_test(source: &MinimalViableSource) -> &format::LocoPacket { | ||
| zerocopy::transmute_ref!(source) | ||
| } |
Sorry, the diff of this file is not supported yet
| #[path = "formats/coco.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn codegen_test(source: &[u8], count: usize) -> Option<&format::CocoPacket> { | ||
| zerocopy::TryFromBytes::try_ref_from_bytes_with_elems(source, count).ok() | ||
| } |
Sorry, the diff of this file is not supported yet
| #[path = "formats/coco.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn codegen_test(source: &[u8]) -> Option<&format::CocoPacket> { | ||
| zerocopy::TryFromBytes::try_ref_from_bytes(source).ok() | ||
| } |
Sorry, the diff of this file is not supported yet
| #[path = "formats/coco.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn codegen_test(source: &[u8], count: usize) -> Option<&format::CocoPacket> { | ||
| match zerocopy::TryFromBytes::try_ref_from_prefix_with_elems(source, count) { | ||
| Ok((packet, _rest)) => Some(packet), | ||
| _ => None, | ||
| } | ||
| } |
Sorry, the diff of this file is not supported yet
| #[path = "formats/coco.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn codegen_test(source: &[u8]) -> Option<&format::CocoPacket> { | ||
| match zerocopy::TryFromBytes::try_ref_from_prefix(source) { | ||
| Ok((packet, _rest)) => Some(packet), | ||
| _ => None, | ||
| } | ||
| } |
Sorry, the diff of this file is not supported yet
| #[path = "formats/coco.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn codegen_test(source: &[u8], count: usize) -> Option<&format::CocoPacket> { | ||
| match zerocopy::TryFromBytes::try_ref_from_suffix_with_elems(source, count) { | ||
| Ok((_rest, packet)) => Some(packet), | ||
| _ => None, | ||
| } | ||
| } |
Sorry, the diff of this file is not supported yet
| #[path = "formats/coco.rs"] | ||
| mod format; | ||
| #[unsafe(no_mangle)] | ||
| fn codegen_test(source: &[u8]) -> Option<&format::CocoPacket> { | ||
| match zerocopy::TryFromBytes::try_ref_from_suffix(source) { | ||
| Ok((_rest, packet)) => Some(packet), | ||
| _ => None, | ||
| } | ||
| } |
Sorry, the diff of this file is not supported yet
| use zerocopy_derive::*; | ||
| #[path = "formats/coco.rs"] | ||
| mod format; | ||
| #[derive(IntoBytes, KnownLayout, Immutable)] | ||
| #[repr(C, align(2))] | ||
| struct MinimalViableSource { | ||
| header: [u8; 4], | ||
| trailer: [[u8; 2]], | ||
| } | ||
| #[unsafe(no_mangle)] | ||
| fn codegen_test(source: &MinimalViableSource) -> Option<&format::CocoPacket> { | ||
| zerocopy::try_transmute_ref!(source).ok() | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display