Beispiel
axum-macros 0.5.1: FromRef
Verifiziertes Beispiel für cargo axum-macros 0.5.1: FromRef. Der Vertrag lief auf rust 1 · linux alpine/x64 · docker und bestand.
sha256:8f2a1baa91daa56676b6a235f83baa33399fd2ffbef8201be5f893d4e946fc21
Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen.
Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen.
MIT-0
Ausführungsbelege
Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.
- Beleggrundlage
- Signierter Vertrag bestanden
- Verifizierungsbelege
- 1
- Signaturschlüssel, die es gebaut haben
- 1
Deklarierte Umgebung
linux x64 cargo
Umgebungen der Verifizierungsläufe
| Umgebung | Contract | Stufen | Lauf |
|---|---|---|---|
| rust 1 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · cargo@1rust:1-alpine@sha256:a10e64dd139b… |
2026-11-16 |
Fall
HOW- Ziel
- verify FromRef in pkg:cargo/axum-macros@0.5.1
- Pakete
- Symbole
-
- FromRef
- Erstellt
- 2026-11-16T23:03:17Z
Contract
- #[derive(axum_macros::FromRef)] expands to impl ::axum::extract::FromRef<State> for each unskipped field type, requiring the axum crate in scope rather than axum-core alone
- Derived FromRef<State> extracts cloned named-struct and tuple-struct substates via SubState::from_ref(&state)
- #[from_ref(skip)] omits non-Clone or duplicate-typed fields from FromRef<State> derivation without requiring Clone on skipped fields
- Derived FromRef<State> integrates with axum::extract::State<SubState>::from_request_parts(&mut parts, &state)
Dateien
- Cargo.lock
- Cargo.toml
- PROMPT.md
- csx.json
- spec.json
- src/main.rs
Quelltext
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "axum"
version = "0.8.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "31b698c5f9a010f6573133b09e0de5408834d0c82f8d7475a89fc1867a71cd90"
dependencies = [
"axum-core",
"bytes",
"futures-util",
"http",
"http-body",
"http-body-util",
"itoa",
"matchit",
"memchr",
"mime",
"percent-encoding",
"pin-project-lite",
"serde_core",
"sync_wrapper",
"tower",
"tower-layer",
"tower-service",
]
[[package]]
name = "axum-core"
version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08c78f31d7b1291f7ee735c1c6780ccde7785daae9a9206026862dab7d8792d1"
dependencies = [
"bytes",
"futures-core",
"http",
"http-body",
"http-body-util",
"mime",
"pin-project-lite",
"sync_wrapper",
"tower-layer",
"tower-service",
]
[[package]]
name = "axum-macros"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7aa268c23bfbbd2c4363b9cd302a4f504fb2a9dfe7e3451d66f35dd392e20aca"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.119",
]
[[package]]
name = "bytes"
version = "1.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04"
[[package]]
name = "futures-core"
version = "0.3.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e"
[[package]]
name = "futures-task"
version = "0.3.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd417de3d1d015fc3bfd2b1ea46dfc7bab72ef86f1cc7cc9c78e728b34a6d1fd"
[[package]]
name = "futures-util"
version = "0.3.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc"
dependencies = [
"futures-core",
"futures-task",
"pin-project-lite",
"slab",
]
[[package]]
name = "http"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "918d3568bebf352712bc2ef3d46a8bcf1a75b373be6539de198e9105cbbf9ce0"
dependencies = [
"bytes",
"itoa",
]
[[package]]
name = "http-body"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca2a8f2913ee65f60facd6a5905613afaa448497a0230cc41ce022d93290bc2c"
dependencies = [
"bytes",
"http",
]
[[package]]
name = "http-body-util"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23169fe34a5fbcdd3f3862e78fb9b6fccd5f02a6dc6f732547005d45631ce71c"
dependencies = [
"bytes",
"futures-core",
"http",
"http-body",
"pin-project-lite",
]
[[package]]
name = "itoa"
version = "1.0.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4"
[[package]]
name = "matchit"
version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3"
[[package]]
name = "memchr"
version = "2.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
[[package]]
name = "mime"
version = "0.3.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d5848f5a9e8117cf94f2f90faac24a87ff81600ff8628c1e3deaab572e76bfa1"
[[package]]
name = "percent-encoding"
version = "2.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220"
[[package]]
name = "pin-project-lite"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd"
[[package]]
name = "proc-macro2"
version = "1.0.107"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
dependencies = [
"proc-macro2",
]
[[package]]
name = "sample-axum-macros-from-ref"
version = "0.1.0"
dependencies = [
"axum",
"axum-macros",
"http",
]
[[package]]
name = "serde_core"
version = "1.0.229"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.229"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348"
dependencies = [
"proc-macro2",
"quote",
"syn 3.0.10",
]
[[package]]
name = "slab"
version = "0.4.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5"
[[package]]
name = "syn"
version = "2.0.119"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "syn"
version = "3.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "sync_wrapper"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263"
[[package]]
name = "tower"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4"
dependencies = [
"futures-core",
"futures-util",
"pin-project-lite",
"sync_wrapper",
"tower-layer",
"tower-service",
]
[[package]]
name = "tower-layer"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e"
[[package]]
name = "tower-service"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3"
[[package]]
name = "unicode-ident"
version = "1.0.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
[package]
name = "sample-axum-macros-from-ref"
version = "0.1.0"
edition = "2021"
publish = false
[dependencies]
axum-macros = "=0.5.1"
axum = { version = "0.8", default-features = false }
http = "1"
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: verify FromRef in pkg:cargo/axum-macros@0.5.1
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:cargo/axum-macros@0.5.1
Demonstrate these symbols/APIs:
- FromRef
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
{"case":{"caseId":"case:sha256:70aef632f663cae41813a7391555260049d416a47a95eec86806ab8ec0cb7ceb","contract":["#[derive(axum_macros::FromRef)] expands to impl ::axum::extract::FromRef\u003cState\u003e for each unskipped field type, requiring the axum crate in scope rather than axum-core alone","Derived FromRef\u003cState\u003e extracts cloned named-struct and tuple-struct substates via SubState::from_ref(\u0026state)","#[from_ref(skip)] omits non-Clone or duplicate-typed fields from FromRef\u003cState\u003e derivation without requiring Clone on skipped fields","Derived FromRef\u003cState\u003e integrates with axum::extract::State\u003cSubState\u003e::from_request_parts(\u0026mut parts, \u0026state)"],"goal":"verify FromRef in pkg:cargo/axum-macros@0.5.1","kind":"HOW","packages":["pkg:cargo/axum-macros@0.5.1"],"schemaVersion":1,"symbols":["FromRef"]},"contractCommand":["cargo","run","--offline"],"environment":{"arch":"x64","ecosystem":"cargo","os":"linux","packageManager":"cargo","schemaVersion":1},"license":"MIT-0","packages":["pkg:cargo/axum-macros@0.5.1"],"schemaVersion":1,"subject":"pkg:cargo/axum-macros@0.5.1","symbols":["FromRef"],"verifierAdapter":"cargo@1"}
{
"schemaVersion": 1,
"goal": "verify FromRef in pkg:cargo/axum-macros@0.5.1",
"kind": "HOW",
"packages": [
"pkg:cargo/axum-macros@0.5.1"
],
"symbols": [
"FromRef"
]
}
use axum::extract::{FromRef, FromRequestParts, State};
use axum_macros::FromRef;
use http::Request;
use std::future::Future;
use std::pin::pin;
use std::task::{Context, Poll, Waker};
#[derive(Clone, Debug, PartialEq, Eq)]
struct ServiceEndpoint {
url: String,
}
#[derive(Clone, Debug, PartialEq, Eq)]
struct ApiConfig {
timeout_ms: u64,
}
// Non-Clone handle: #[from_ref(skip)] omits it from FromRef derivation
struct InternalMetrics {
counter: u64,
}
#[derive(FromRef)]
struct AppState {
endpoint: ServiceEndpoint,
config: ApiConfig,
#[from_ref(skip)]
metrics: InternalMetrics,
#[from_ref(skip)]
fallback_config: ApiConfig,
}
#[derive(FromRef)]
struct TupleState(ServiceEndpoint, #[from_ref(skip)] InternalMetrics);
fn block_on<F: Future>(fut: F) -> F::Output {
let mut fut = pin!(fut);
let waker = Waker::noop();
let mut cx = Context::from_waker(waker);
loop {
if let Poll::Ready(val) = fut.as_mut().poll(&mut cx) {
return val;
}
}
}
fn main() {
let app_state = AppState {
endpoint: ServiceEndpoint {
url: "http://localhost:8080".to_owned(),
},
config: ApiConfig { timeout_ms: 500 },
metrics: InternalMetrics { counter: 42 },
fallback_config: ApiConfig { timeout_ms: 2000 },
};
assert_eq!(app_state.metrics.counter, 42);
assert_eq!(app_state.fallback_config.timeout_ms, 2000);
// 1. Direct substate extraction via derived FromRef<AppState> on named struct fields
let endpoint = ServiceEndpoint::from_ref(&app_state);
assert_eq!(
endpoint,
ServiceEndpoint {
url: "http://localhost:8080".to_owned(),
}
);
let cfg = ApiConfig::from_ref(&app_state);
assert_eq!(cfg, ApiConfig { timeout_ms: 500 });
// 2. Derived FromRef<AppState> integrates with axum::extract::State<SubState> via FromRequestParts<AppState>
let req = Request::builder()
.uri("http://localhost/health")
.body(())
.unwrap();
let (mut parts, _) = req.into_parts();
let State(extracted_endpoint): State<ServiceEndpoint> =
block_on(State::<ServiceEndpoint>::from_request_parts(&mut parts, &app_state)).unwrap();
assert_eq!(extracted_endpoint.url, "http://localhost:8080");
let State(extracted_cfg): State<ApiConfig> =
block_on(State::<ApiConfig>::from_request_parts(&mut parts, &app_state)).unwrap();
assert_eq!(extracted_cfg.timeout_ms, 500);
// 3. Derived FromRef on tuple structs with #[from_ref(skip)] on non-Clone elements
let tuple_state = TupleState(
ServiceEndpoint {
url: "http://localhost:8081".to_owned(),
},
InternalMetrics { counter: 7 },
);
assert_eq!(tuple_state.1.counter, 7);
let secondary_endpoint = ServiceEndpoint::from_ref(&tuple_state);
assert_eq!(secondary_endpoint.url, "http://localhost:8081");
}
Ursprungs-Seeder
anonym