Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ jobs:
#
# TODO(#1228): Use `jq` to parse these from `Cargo.toml` instead of
# hard-coding them once we've gotten it working again.
METADATA_DOCS_RS_RUSTDOC_ARGS='--cfg doc_cfg --generate-link-to-definition'
METADATA_DOCS_RS_RUSTDOC_ARGS='--cfg doc_cfg --generate-link-to-definition --extend-css rustdoc/style.css'
export RUSTDOCFLAGS="-Z unstable-options --document-hidden-items $METADATA_DOCS_RS_RUSTDOC_ARGS"

# TODO: Use `./cargo.sh` instead once we've debugged why it won't work.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pinned-nightly = "nightly-2026-01-25"

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "doc_cfg", "--generate-link-to-definition"]
rustdoc-args = ["--cfg", "doc_cfg", "--generate-link-to-definition", "--extend-css", "rustdoc/style.css"]

[package.metadata.playground]
features = ["__internal_use_only_features_that_work_on_stable"]
Expand Down
21 changes: 0 additions & 21 deletions benches/formats/coco.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,3 @@
// Copyright 2026 The Fuchsia Authors
//
// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
// This file may not be copied, modified, or distributed except according to
// those terms.

//! This modules defines two formats similar to the one used to illustrate the
//! examples of [`zerocopy::TryFromBytes`]. The basic structure of these formats
//! is a [`Packet`], which has a parameterizable leading field, followed by
//! two-fixed byte fields, followed by a dynamically sized field. This format is
//! consumed by our benchmarks either as a [`CocoPacket`] (which begins with the
//! leading bytes `0xC0C0`), or a [`LocoPacket`] (which begins two bytes of any
//! value). Both formats share the following qualities which stress-test our
//! benchmarks:
//!
//! - They have a minimum alignment of two.
//! - They have a minimum size of four bytes.
//! - They have an even size.

use zerocopy_derive::*;

// The only valid value of this type are the bytes `0xC0C0`.
Expand Down
12 changes: 1 addition & 11 deletions benches/ref_from_bytes.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
// Copyright 2026 The Fuchsia Authors
//
// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
// This file may not be copied, modified, or distributed except according to
// those terms.

use zerocopy::FromBytes;

#[path = "formats/coco.rs"]
mod format;

#[unsafe(no_mangle)]
fn codegen_test(source: &[u8]) -> Option<&format::LocoPacket> {
FromBytes::ref_from_bytes(source).ok()
zerocopy::FromBytes::ref_from_bytes(source).ok()
}
12 changes: 1 addition & 11 deletions benches/ref_from_bytes_with_elems.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
// Copyright 2026 The Fuchsia Authors
//
// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
// This file may not be copied, modified, or distributed except according to
// those terms.

use zerocopy::FromBytes;

#[path = "formats/coco.rs"]
mod format;

#[unsafe(no_mangle)]
fn codegen_test(source: &[u8], count: usize) -> Option<&format::LocoPacket> {
FromBytes::ref_from_bytes_with_elems(source, count).ok()
zerocopy::FromBytes::ref_from_bytes_with_elems(source, count).ok()
}
12 changes: 1 addition & 11 deletions benches/ref_from_prefix.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
// Copyright 2026 The Fuchsia Authors
//
// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
// This file may not be copied, modified, or distributed except according to
// those terms.

use zerocopy::FromBytes;

#[path = "formats/coco.rs"]
mod format;

#[unsafe(no_mangle)]
fn codegen_test(source: &[u8]) -> Option<&format::LocoPacket> {
match FromBytes::ref_from_prefix(source) {
match zerocopy::FromBytes::ref_from_prefix(source) {
Ok((packet, _rest)) => Some(packet),
_ => None,
}
Expand Down
12 changes: 1 addition & 11 deletions benches/ref_from_prefix_with_elems.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
// Copyright 2026 The Fuchsia Authors
//
// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
// This file may not be copied, modified, or distributed except according to
// those terms.

use zerocopy::FromBytes;

#[path = "formats/coco.rs"]
mod format;

#[unsafe(no_mangle)]
fn codegen_test(source: &[u8], count: usize) -> Option<&format::LocoPacket> {
match FromBytes::ref_from_prefix_with_elems(source, count) {
match zerocopy::FromBytes::ref_from_prefix_with_elems(source, count) {
Ok((packet, _rest)) => Some(packet),
_ => None,
}
Expand Down
12 changes: 1 addition & 11 deletions benches/ref_from_suffix.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
// Copyright 2026 The Fuchsia Authors
//
// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
// This file may not be copied, modified, or distributed except according to
// those terms.

use zerocopy::FromBytes;

#[path = "formats/coco.rs"]
mod format;

#[unsafe(no_mangle)]
fn codegen_test(source: &[u8]) -> Option<&format::LocoPacket> {
match FromBytes::ref_from_suffix(source) {
match zerocopy::FromBytes::ref_from_suffix(source) {
Ok((_rest, packet)) => Some(packet),
_ => None,
}
Expand Down
12 changes: 1 addition & 11 deletions benches/ref_from_suffix_with_elems.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
// Copyright 2026 The Fuchsia Authors
//
// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
// This file may not be copied, modified, or distributed except according to
// those terms.

use zerocopy::FromBytes;

#[path = "formats/coco.rs"]
mod format;

#[unsafe(no_mangle)]
fn codegen_test(source: &[u8], count: usize) -> Option<&format::LocoPacket> {
match FromBytes::ref_from_suffix_with_elems(source, count) {
match zerocopy::FromBytes::ref_from_suffix_with_elems(source, count) {
Ok((_rest, packet)) => Some(packet),
_ => None,
}
Expand Down
11 changes: 1 addition & 10 deletions benches/transmute_ref.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
// Copyright 2026 The Fuchsia Authors
//
// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
// This file may not be copied, modified, or distributed except according to
// those terms.

use zerocopy::transmute_ref;
use zerocopy_derive::*;

#[path = "formats/coco.rs"]
Expand All @@ -21,5 +12,5 @@ struct MinimalViableSource {

#[unsafe(no_mangle)]
fn codegen_test(source: &MinimalViableSource) -> &format::LocoPacket {
transmute_ref!(source)
zerocopy::transmute_ref!(source)
}
12 changes: 1 addition & 11 deletions benches/try_ref_from_bytes.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
// Copyright 2026 The Fuchsia Authors
//
// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
// This file may not be copied, modified, or distributed except according to
// those terms.

use zerocopy::TryFromBytes;

#[path = "formats/coco.rs"]
mod format;

#[unsafe(no_mangle)]
fn codegen_test(source: &[u8]) -> Option<&format::CocoPacket> {
TryFromBytes::try_ref_from_bytes(source).ok()
zerocopy::TryFromBytes::try_ref_from_bytes(source).ok()
}
12 changes: 1 addition & 11 deletions benches/try_ref_from_bytes_with_elems.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
// Copyright 2026 The Fuchsia Authors
//
// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
// This file may not be copied, modified, or distributed except according to
// those terms.

use zerocopy::TryFromBytes;

#[path = "formats/coco.rs"]
mod format;

#[unsafe(no_mangle)]
fn codegen_test(source: &[u8], count: usize) -> Option<&format::CocoPacket> {
TryFromBytes::try_ref_from_bytes_with_elems(source, count).ok()
zerocopy::TryFromBytes::try_ref_from_bytes_with_elems(source, count).ok()
}
12 changes: 1 addition & 11 deletions benches/try_ref_from_prefix.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
// Copyright 2026 The Fuchsia Authors
//
// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
// This file may not be copied, modified, or distributed except according to
// those terms.

use zerocopy::TryFromBytes;

#[path = "formats/coco.rs"]
mod format;

#[unsafe(no_mangle)]
fn codegen_test(source: &[u8]) -> Option<&format::CocoPacket> {
match TryFromBytes::try_ref_from_prefix(source) {
match zerocopy::TryFromBytes::try_ref_from_prefix(source) {
Ok((packet, _rest)) => Some(packet),
_ => None,
}
Expand Down
12 changes: 1 addition & 11 deletions benches/try_ref_from_prefix_with_elems.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
// Copyright 2026 The Fuchsia Authors
//
// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
// This file may not be copied, modified, or distributed except according to
// those terms.

use zerocopy::TryFromBytes;

#[path = "formats/coco.rs"]
mod format;

#[unsafe(no_mangle)]
fn codegen_test(source: &[u8], count: usize) -> Option<&format::CocoPacket> {
match TryFromBytes::try_ref_from_prefix_with_elems(source, count) {
match zerocopy::TryFromBytes::try_ref_from_prefix_with_elems(source, count) {
Ok((packet, _rest)) => Some(packet),
_ => None,
}
Expand Down
12 changes: 1 addition & 11 deletions benches/try_ref_from_suffix.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
// Copyright 2026 The Fuchsia Authors
//
// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
// This file may not be copied, modified, or distributed except according to
// those terms.

use zerocopy::TryFromBytes;

#[path = "formats/coco.rs"]
mod format;

#[unsafe(no_mangle)]
fn codegen_test(source: &[u8]) -> Option<&format::CocoPacket> {
match TryFromBytes::try_ref_from_suffix(source) {
match zerocopy::TryFromBytes::try_ref_from_suffix(source) {
Ok((_rest, packet)) => Some(packet),
_ => None,
}
Expand Down
12 changes: 1 addition & 11 deletions benches/try_ref_from_suffix_with_elems.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
// Copyright 2026 The Fuchsia Authors
//
// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
// This file may not be copied, modified, or distributed except according to
// those terms.

use zerocopy::TryFromBytes;

#[path = "formats/coco.rs"]
mod format;

#[unsafe(no_mangle)]
fn codegen_test(source: &[u8], count: usize) -> Option<&format::CocoPacket> {
match TryFromBytes::try_ref_from_suffix_with_elems(source, count) {
match zerocopy::TryFromBytes::try_ref_from_suffix_with_elems(source, count) {
Ok((_rest, packet)) => Some(packet),
_ => None,
}
Expand Down
11 changes: 1 addition & 10 deletions benches/try_transmute_ref.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
// Copyright 2026 The Fuchsia Authors
//
// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
// This file may not be copied, modified, or distributed except according to
// those terms.

use zerocopy::try_transmute_ref;
use zerocopy_derive::*;

#[path = "formats/coco.rs"]
Expand All @@ -21,5 +12,5 @@ struct MinimalViableSource {

#[unsafe(no_mangle)]
fn codegen_test(source: &MinimalViableSource) -> Option<&format::CocoPacket> {
try_transmute_ref!(source).ok()
zerocopy::try_transmute_ref!(source).ok()
}
53 changes: 53 additions & 0 deletions rustdoc/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
Copyright 2026 The Fuchsia Authors

Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
<LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
This file may not be copied, modified, or distributed except according to
those terms.
*/

.codegen-tabs {
display: grid;
grid-template-columns: repeat(3, minmax(200px, 1fr));
grid-template-rows: auto 1fr;
column-gap: 1rem;
}

.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;
}

.codegen-tabs details {
display: grid;
grid-column: 1 / -1;
grid-row: 1 / span 2;
grid-template-columns: subgrid;
grid-template-rows: subgrid;
}

.codegen-tabs summary {
display: grid;
grid-column: var(--n) / span 1;
grid-row: 1;
z-index: 1;
border-bottom: 2px solid var(--headings-border-bottom-color);
cursor: pointer;
}

.codegen-tabs details[open] :is(summary) {
background-color: var(--code-block-background-color);
border-bottom-color: var(--target-border-color);
}

.codegen-tabs details::details-content {
grid-column: 1 / -1;
grid-row: 2;
}

.codegen-tabs details:not([open])::details-content {
display: none;
}
Comment thread
jswrenn marked this conversation as resolved.
Loading
Loading