Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

zerocopy

Package Overview
Dependencies
Maintainers
1
Versions
160
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zerocopy - cargo Package Compare versions

Comparing version
0.8.46-alpha.3
to
0.8.46
+9
benches/as_bytes_dynamic_size.rs
use zerocopy::*;
#[path = "formats/coco_dynamic_size.rs"]
mod format;
#[unsafe(no_mangle)]
fn bench_as_bytes_dynamic_size(source: &format::CocoPacket) -> &[u8] {
source.as_bytes()
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

use zerocopy::*;
#[path = "formats/coco_static_size.rs"]
mod format;
#[unsafe(no_mangle)]
fn bench_as_bytes_static_size(source: &format::CocoPacket) -> &[u8] {
source.as_bytes()
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

use zerocopy::*;
#[path = "formats/coco_dynamic_padding.rs"]
mod format;
#[unsafe(no_mangle)]
fn bench_split_at_dynamic_padding(
source: &format::CocoPacket,
len: usize,
) -> Option<Split<&format::CocoPacket>> {
source.split_at(len)
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

use zerocopy::*;
#[path = "formats/coco_dynamic_size.rs"]
mod format;
#[unsafe(no_mangle)]
fn bench_split_at_dynamic_size(
source: &format::CocoPacket,
len: usize,
) -> Option<Split<&format::CocoPacket>> {
source.split_at(len)
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

use zerocopy::*;
#[path = "formats/coco_dynamic_padding.rs"]
mod format;
#[unsafe(no_mangle)]
unsafe fn bench_split_at_unchecked_dynamic_padding(
source: &format::CocoPacket,
len: usize,
) -> Split<&format::CocoPacket> {
unsafe { source.split_at_unchecked(len) }
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

use zerocopy::*;
#[path = "formats/coco_dynamic_size.rs"]
mod format;
#[unsafe(no_mangle)]
unsafe fn bench_split_at_unchecked_dynamic_size(
source: &format::CocoPacket,
len: usize,
) -> Split<&format::CocoPacket> {
unsafe { source.split_at_unchecked(len) }
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

use zerocopy::*;
#[path = "formats/coco_dynamic_padding.rs"]
mod format;
#[unsafe(no_mangle)]
fn bench_split_via_immutable_dynamic_padding(
split: Split<&format::CocoPacket>,
) -> (&format::CocoPacket, &[[u8; 3]]) {
split.via_immutable()
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

use zerocopy::*;
#[path = "formats/coco_dynamic_size.rs"]
mod format;
#[unsafe(no_mangle)]
fn bench_split_via_immutable_dynamic_size(
split: Split<&format::CocoPacket>,
) -> (&format::CocoPacket, &[[u8; 2]]) {
split.via_immutable()
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

use zerocopy::*;
#[path = "formats/coco_dynamic_padding.rs"]
mod format;
#[unsafe(no_mangle)]
fn bench_split_via_runtime_check_dynamic_padding(
split: Split<&format::CocoPacket>,
) -> Option<(&format::CocoPacket, &[[u8; 3]])> {
split.via_runtime_check().ok()
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

use zerocopy::*;
#[path = "formats/coco_dynamic_size.rs"]
mod format;
#[unsafe(no_mangle)]
fn bench_split_via_runtime_check_dynamic_size(
split: Split<&format::CocoPacket>,
) -> Option<(&format::CocoPacket, &[[u8; 2]])> {
split.via_runtime_check().ok()
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

use zerocopy::*;
#[path = "formats/coco_dynamic_padding.rs"]
mod format;
#[unsafe(no_mangle)]
unsafe fn bench_split_via_unchecked_dynamic_padding(
split: Split<&format::CocoPacket>,
) -> (&format::CocoPacket, &[[u8; 3]]) {
unsafe { split.via_unchecked() }
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

use zerocopy::*;
#[path = "formats/coco_dynamic_size.rs"]
mod format;
#[unsafe(no_mangle)]
unsafe fn bench_split_via_unchecked_dynamic_size(
split: Split<&format::CocoPacket>,
) -> (&format::CocoPacket, &[[u8; 2]]) {
unsafe { split.via_unchecked() }
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

use zerocopy::*;
#[path = "formats/coco_dynamic_size.rs"]
mod format;
#[unsafe(no_mangle)]
fn bench_write_to_dynamic_size(source: &format::CocoPacket, destination: &mut [u8]) -> Option<()> {
source.write_to(destination).ok()
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

use zerocopy::*;
#[path = "formats/coco_dynamic_size.rs"]
mod format;
#[unsafe(no_mangle)]
fn bench_write_to_prefix_dynamic_size(
source: &format::CocoPacket,
destination: &mut [u8],
) -> Option<()> {
source.write_to_prefix(destination).ok()
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

use zerocopy::*;
#[path = "formats/coco_static_size.rs"]
mod format;
#[unsafe(no_mangle)]
fn bench_write_to_prefix_static_size(
source: &format::CocoPacket,
destination: &mut [u8],
) -> Option<()> {
source.write_to_prefix(destination).ok()
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

use zerocopy::*;
#[path = "formats/coco_static_size.rs"]
mod format;
#[unsafe(no_mangle)]
fn bench_write_to_static_size(source: &format::CocoPacket, destination: &mut [u8]) -> Option<()> {
source.write_to(destination).ok()
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

use zerocopy::*;
#[path = "formats/coco_dynamic_size.rs"]
mod format;
#[unsafe(no_mangle)]
fn bench_write_to_suffix_dynamic_size(
source: &format::CocoPacket,
destination: &mut [u8],
) -> Option<()> {
source.write_to_suffix(destination).ok()
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

use zerocopy::*;
#[path = "formats/coco_static_size.rs"]
mod format;
#[unsafe(no_mangle)]
fn bench_write_to_suffix_static_size(
source: &format::CocoPacket,
destination: &mut [u8],
) -> Option<()> {
source.write_to_suffix(destination).ok()
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

#!/usr/bin/env python3
import argparse
import json
import re
import sys
import posixpath
import os
# Exit codes
SUCCESS = 0
NOT_APPROVED = 1
TECHNICAL_ERROR = 255
def main():
parser = argparse.ArgumentParser(
description="Validate PR changes against auto-approver rules."
)
parser.add_argument(
"--config",
default=".github/auto-approvers.json",
help="Path to the rules JSON.",
)
parser.add_argument(
"--changed-files", help="Path to the fetched changed files JSON."
)
parser.add_argument(
"--expected-count", type=int, help="Total number of files expected in the PR."
)
parser.add_argument(
"--contributors", nargs="+", help="List of GitHub usernames to validate."
)
parser.add_argument(
"--check-config",
action="store_true",
help="Only validate the configuration file and exit.",
)
args = parser.parse_args()
# REGEX: Strict path structure, prevents absolute paths and weird characters
VALID_PATH = re.compile(r"^([a-zA-Z0-9_.-]+/)+$")
# Load and validate config
try:
with open(args.config) as f:
rules = json.load(f)
except FileNotFoundError:
print(f"::error::❌ Config file not found at {args.config}")
sys.exit(TECHNICAL_ERROR)
except json.JSONDecodeError as e:
print(f"::error::❌ Failed to parse config JSON: {e}")
sys.exit(TECHNICAL_ERROR)
safe_rules = {}
for directory, users in rules.items():
if not isinstance(users, list):
print(
f"::error::❌ Users for '{directory}' must be a JSON array (list), not a string."
)
sys.exit(TECHNICAL_ERROR)
if not VALID_PATH.match(directory) or ".." in directory.split("/"):
print(f"::error::❌ Invalid config path: {directory}")
sys.exit(TECHNICAL_ERROR)
safe_rules[directory] = [str(u).lower() for u in users]
if not args.check_config:
# Validate that required arguments are present if not in --check-config mode
if not (
args.changed_files and args.expected_count is not None and args.contributors
):
print(
"::error::❌ Missing required arguments: --changed-files, --expected-count, and --contributors are required unless --check-config is used."
)
sys.exit(TECHNICAL_ERROR)
# Load and flatten changed files
try:
with open(args.changed_files) as f:
file_objects = json.load(f)
except FileNotFoundError:
print(f"::error::❌ Changed files JSON not found at {args.changed_files}")
sys.exit(TECHNICAL_ERROR)
except json.JSONDecodeError as e:
print(f"::error::❌ Failed to parse changed files JSON: {e}")
sys.exit(TECHNICAL_ERROR)
if not file_objects or len(file_objects) != args.expected_count:
print(
f"::error::❌ File truncation mismatch or empty PR. Expected {args.expected_count}, got {len(file_objects) if file_objects else 0}."
)
sys.exit(TECHNICAL_ERROR)
if not all(isinstance(obj, list) for obj in file_objects):
print("::error::❌ Invalid payload format. Expected a list of lists.")
sys.exit(TECHNICAL_ERROR)
changed_files = [path for obj in file_objects for path in obj]
# Validate every file against every contributor
contributors = set(str(c).lower() for c in args.contributors)
print(f"👥 Validating contributors: {', '.join(contributors)}")
for raw_file_path in changed_files:
file_path = posixpath.normpath(raw_file_path)
# Find the most specific (longest) matching directory rule.
longest_match_dir = None
for directory in safe_rules.keys():
if file_path.startswith(directory):
if longest_match_dir is None or len(directory) > len(
longest_match_dir
):
longest_match_dir = directory
# First, explicitly fail if the file isn't covered by ANY rule.
if not longest_match_dir:
print(
f"::error::❌ File '{file_path}' does not fall under any configured auto-approve directory."
)
sys.exit(NOT_APPROVED)
# Then, verify every contributor has access to that specific rule.
for user in contributors:
if user not in safe_rules[longest_match_dir]:
print(
f"::error::❌ Contributor @{user} not authorized for '{file_path}'."
)
sys.exit(NOT_APPROVED)
if args.check_config:
print("✅ Configuration is structurally valid")
else:
print("✅ Validation passed")
sys.exit(SUCCESS)
if __name__ == "__main__":
main()
+1
-1
{
"git": {
"sha1": "9072aa0084f33737c6d21fa2bb18e29084128098"
"sha1": "e38763fcad951b7bf33bc9d12b45f6080411917e"
},
"path_in_vcs": ""
}

@@ -10,3 +10,3 @@ use zerocopy_derive::*;

#[derive(FromBytes, KnownLayout, Immutable)]
#[derive(FromBytes, KnownLayout, Immutable, SplitAt)]
#[repr(C, align(4))]

@@ -13,0 +13,0 @@ pub struct Packet<Magic> {

use zerocopy_derive::*;
// The only valid value of this type are the bytes `0xC0C0`.
#[derive(TryFromBytes, KnownLayout, Immutable)]
#[derive(TryFromBytes, KnownLayout, Immutable, IntoBytes)]
#[repr(u16)]

@@ -10,15 +10,19 @@ pub enum C0C0 {

#[derive(FromBytes, KnownLayout, Immutable)]
#[repr(C, align(2))]
pub struct Packet<Magic> {
magic_number: Magic,
mug_size: u8,
temperature: u8,
marshmallows: [[u8; 2]],
macro_rules! define_packet {
($name: ident, $trait: ident, $leading_field: ty) => {
#[derive($trait, KnownLayout, Immutable, IntoBytes, SplitAt)]
#[repr(C, align(2))]
pub struct $name {
magic_number: $leading_field,
mug_size: u8,
temperature: u8,
marshmallows: [[u8; 2]],
}
};
}
/// A packet begining with the magic number `0xC0C0`.
pub type CocoPacket = Packet<C0C0>;
/// Packet begins with bytes 0xC0C0.
define_packet!(CocoPacket, TryFromBytes, C0C0);
/// A packet beginning with any two initialized bytes.
pub type LocoPacket = Packet<[u8; 2]>;
/// Packet begins with any two bytes.
define_packet!(LocoPacket, FromBytes, [u8; 2]);
use zerocopy_derive::*;
// The only valid value of this type are the bytes `0xC0C0`.
#[derive(TryFromBytes, KnownLayout, Immutable)]
#[derive(TryFromBytes, KnownLayout, Immutable, IntoBytes)]
#[repr(u16)]

@@ -10,15 +10,19 @@ pub enum C0C0 {

#[derive(FromBytes, KnownLayout, Immutable)]
#[repr(C, align(2))]
pub struct Packet<Magic> {
magic_number: Magic,
mug_size: u8,
temperature: u8,
marshmallows: [u8; 2],
macro_rules! define_packet {
($name: ident, $trait: ident, $leading_field: ty) => {
#[derive($trait, KnownLayout, Immutable, IntoBytes)]
#[repr(C, align(2))]
pub struct $name {
magic_number: $leading_field,
mug_size: u8,
temperature: u8,
marshmallows: [u8; 2],
}
};
}
/// A packet begining with the magic number `0xC0C0`.
pub type CocoPacket = Packet<C0C0>;
/// Packet begins with bytes 0xC0C0.
define_packet!(CocoPacket, TryFromBytes, C0C0);
/// A packet beginning with any two initialized bytes.
pub type LocoPacket = Packet<[u8; 2]>;
/// Packet begins with any two bytes.
define_packet!(LocoPacket, FromBytes, [u8; 2]);

@@ -90,3 +90,3 @@ # This file is automatically @generated by Cargo.

name = "zerocopy"
version = "0.8.46-alpha.3"
version = "0.8.46"
dependencies = [

@@ -103,5 +103,5 @@ "elain",

name = "zerocopy-derive"
version = "0.8.46-alpha.3"
version = "0.8.46"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8e0373ab36034b4640c5ef2140f32281600481e2ebf74aa2a01b99c78ae71b6"
checksum = "a5f86989a046a79640b9d8867c823349a139367bda96549794fcc3313ce91f4e"
dependencies = [

@@ -108,0 +108,0 @@ "proc-macro2",

@@ -16,3 +16,3 @@ # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO

name = "zerocopy"
version = "0.8.46-alpha.3"
version = "0.8.46"
authors = [

@@ -105,2 +105,10 @@ "Joshua Liebow-Feeser <joshlf@google.com>",

[[bench]]
name = "as_bytes_dynamic_size"
path = "benches/as_bytes_dynamic_size.rs"
[[bench]]
name = "as_bytes_static_size"
path = "benches/as_bytes_static_size.rs"
[[bench]]
name = "read_from_bytes"

@@ -178,2 +186,42 @@ path = "benches/read_from_bytes.rs"

[[bench]]
name = "split_at_dynamic_padding"
path = "benches/split_at_dynamic_padding.rs"
[[bench]]
name = "split_at_dynamic_size"
path = "benches/split_at_dynamic_size.rs"
[[bench]]
name = "split_at_unchecked_dynamic_padding"
path = "benches/split_at_unchecked_dynamic_padding.rs"
[[bench]]
name = "split_at_unchecked_dynamic_size"
path = "benches/split_at_unchecked_dynamic_size.rs"
[[bench]]
name = "split_via_immutable_dynamic_padding"
path = "benches/split_via_immutable_dynamic_padding.rs"
[[bench]]
name = "split_via_immutable_dynamic_size"
path = "benches/split_via_immutable_dynamic_size.rs"
[[bench]]
name = "split_via_runtime_check_dynamic_padding"
path = "benches/split_via_runtime_check_dynamic_padding.rs"
[[bench]]
name = "split_via_runtime_check_dynamic_size"
path = "benches/split_via_runtime_check_dynamic_size.rs"
[[bench]]
name = "split_via_unchecked_dynamic_padding"
path = "benches/split_via_unchecked_dynamic_padding.rs"
[[bench]]
name = "split_via_unchecked_dynamic_size"
path = "benches/split_via_unchecked_dynamic_size.rs"
[[bench]]
name = "transmute"

@@ -274,4 +322,28 @@ path = "benches/transmute.rs"

[[bench]]
name = "write_to_dynamic_size"
path = "benches/write_to_dynamic_size.rs"
[[bench]]
name = "write_to_prefix_dynamic_size"
path = "benches/write_to_prefix_dynamic_size.rs"
[[bench]]
name = "write_to_prefix_static_size"
path = "benches/write_to_prefix_static_size.rs"
[[bench]]
name = "write_to_static_size"
path = "benches/write_to_static_size.rs"
[[bench]]
name = "write_to_suffix_dynamic_size"
path = "benches/write_to_suffix_dynamic_size.rs"
[[bench]]
name = "write_to_suffix_static_size"
path = "benches/write_to_suffix_static_size.rs"
[dependencies.zerocopy-derive]
version = "=0.8.46-alpha.3"
version = "=0.8.46"
optional = true

@@ -297,5 +369,5 @@

[dev-dependencies.zerocopy-derive]
version = "=0.8.46-alpha.3"
version = "=0.8.46"
[target."cfg(any())".dependencies.zerocopy-derive]
version = "=0.8.46-alpha.3"
version = "=0.8.46"

@@ -76,2 +76,20 @@ // Copyright 2025 The Fuchsia Authors

/// `self`'s trailing slice.
///
#[doc = codegen_section!(
header = "h5",
bench = "split_at_unchecked",
format = "coco",
arity = 2,
[
open
@index 1
@title "Unsized"
@variant "dynamic_size"
],
[
@index 2
@title "Dynamically Padded"
@variant "dynamic_padding"
]
)]
#[inline]

@@ -121,2 +139,20 @@ #[must_use]

/// ```
///
#[doc = codegen_section!(
header = "h5",
bench = "split_at",
format = "coco",
arity = 2,
[
open
@index 1
@title "Unsized"
@variant "dynamic_size"
],
[
@index 2
@title "Dynamically Padded"
@variant "dynamic_padding"
]
)]
#[inline]

@@ -141,2 +177,6 @@ #[must_use = "has no side effects"]

/// `self`'s trailing slice.
///
#[doc = codegen_header!("h5", "split_at_mut_unchecked")]
///
/// See [`SplitAt::split_at_unchecked`](#method.split_at_unchecked.codegen).
#[inline]

@@ -196,2 +236,6 @@ #[must_use]

/// ```
///
#[doc = codegen_header!("h5", "split_at_mut")]
///
/// See [`SplitAt::split_at`](#method.split_at.codegen).
#[inline]

@@ -307,2 +351,20 @@ fn split_at_mut(&mut self, l_len: usize) -> Option<Split<&mut Self>> {

/// ```
///
#[doc = codegen_section!(
header = "h5",
bench = "split_via_immutable",
format = "coco",
arity = 2,
[
open
@index 1
@title "Unsized"
@variant "dynamic_size"
],
[
@index 2
@title "Dynamically Padded"
@variant "dynamic_padding"
]
)]
#[must_use = "has no side effects"]

@@ -353,2 +415,6 @@ #[inline(always)]

/// ```
///
#[doc = codegen_header!("h5", "split_via_into_bytes")]
///
/// See [`Split::via_immutable`](#method.split_via_immutable.codegen).
#[must_use = "has no side effects"]

@@ -399,2 +465,6 @@ #[inline(always)]

/// ```
///
#[doc = codegen_header!("h5", "split_via_unaligned")]
///
/// See [`Split::via_immutable`](#method.split_via_immutable.codegen).
#[must_use = "has no side effects"]

@@ -469,2 +539,20 @@ #[inline(always)]

/// ```
///
#[doc = codegen_section!(
header = "h5",
bench = "split_via_runtime_check",
format = "coco",
arity = 2,
[
open
@index 1
@title "Unsized"
@variant "dynamic_size"
],
[
@index 2
@title "Dynamically Padded"
@variant "dynamic_padding"
]
)]
#[must_use = "has no side effects"]

@@ -489,2 +577,20 @@ #[inline(always)]

/// condition is dependent on the length of the left portion.
///
#[doc = codegen_section!(
header = "h5",
bench = "split_via_unchecked",
format = "coco",
arity = 2,
[
open
@index 1
@title "Unsized"
@variant "dynamic_size"
],
[
@index 2
@title "Dynamically Padded"
@variant "dynamic_padding"
]
)]
#[must_use = "has no side effects"]

@@ -555,2 +661,6 @@ #[inline(always)]

/// ```
///
/// # Code Generation
///
/// See [`Split::via_immutable`](#method.split_via_immutable.codegen).
#[must_use = "has no side effects"]

@@ -608,2 +718,6 @@ #[inline(always)]

/// ```
///
/// # Code Generation
///
/// See [`Split::via_immutable`](#method.split_via_immutable.codegen).
#[must_use = "has no side effects"]

@@ -663,2 +777,6 @@ #[inline(always)]

/// ```
///
/// # Code Generation
///
/// See [`Split::via_runtime_check`](#method.split_via_runtime_check.codegen).
#[must_use = "has no side effects"]

@@ -682,2 +800,6 @@ #[inline(always)]

/// types, this condition is dependent on the length of the left portion.
///
/// # Code Generation
///
/// See [`Split::via_unchecked`](#method.split_via_unchecked.codegen).
#[must_use = "has no side effects"]

@@ -684,0 +806,0 @@ #[inline(always)]

@@ -41,4 +41,5 @@ // Copyright 2026 The Fuchsia Authors

let cargo_asm = |directive: &Directive| {
Command::new("cargo")
Command::new("./cargo.sh")
.args([
"+nightly",
"asm",

@@ -45,0 +46,0 @@ "--quiet",

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